HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Linear Data Structures: Arrays > problem:


51127 - Maze solver

Section problems

• 51246 - Swap largest word, reverse ...
• 50431 - Sultan's Game
• 50420 - Teachers Sightseeing
• 50977 - Gaussian Elimination
• 50395 - Page "Like" Averages
• 50516 - Lines
• 50446 - Snake
• 50345 - Orders
• 51127 - Maze solver
• 50822 - Linked List
• 51126 - Dr. Fllanxha
• 50529 - Row to Table
• 50499 - Table to Row
• 50823 - Secret Number
• 50853 - Parking Place
• 50990 - Two Neighbors
• 50496 - Falling Bricks

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Question by Ibrahim Mesecan.

Maze solver

You are given a maze where the walls are encoded with the numbers:
  • 1: There is a wall at the top and it is blocked
  • 2: Right of the cell is blocked
  • 4: Bottom of the cell is blocked
  • 8: Left of the cell is blocked
Thus, 12 means there are walls on the left and bottom of the cell and the doors on the other two walls are open.

Question: Write a program that reads a 2D array of integers, and defines the shortest path from upper left corner to the bottom right corner.

Input specification: First, you will be given two numbers (n and m) size of maze. Then, you will be given m numbers in the following n lines where the numbers are between 0 and 15 and 1 ≤ (n and m) ≤ 100.

Output specification: Show one integer: minimum number of steps to reach. Show minus 1 if there is no path.

Sample Input 1 Sample Input 2
6 5
11 9 1 5 7
8 6 10 13 3
10 11 8 3 10
14 8 6 12 2
13 4 3 11 10
13 5 6 12 6
3 4
11 9 5 7
12 4 5 3
13 5 5 6
Sample Output 1 Sample Output 2
12 6



Для отправки решений необходимо выполнить вход.

www.contester.ru