#K60852. Maze Minimum Steps
Maze Minimum Steps
Maze Minimum Steps
Tom is lost in a maze represented by a grid of dimensions . Each cell of the grid is either an empty space (denoted by 0) or an obstacle (denoted by 1). Tom starts at the top-left corner (cell (0, 0)) and must reach the bottom-right corner (cell ). He can move in four directions: up, down, left, or right, but he cannot move through cells containing obstacles. Your task is to determine the minimum number of steps required for Tom to reach his destination. If there is no valid path, output -1.
Note: The grid is provided via standard input. Each test case begins with two integers representing the dimensions of the grid followed by the grid rows.
inputFormat
Input is given from standard input (stdin). The first line contains two integers and , where is the number of rows and is the number of columns in the grid. This is followed by lines, each containing space-separated integers (either 0 or 1) representing the grid.
outputFormat
Output a single integer to standard output (stdout) representing the minimum number of steps required for Tom to reach from the top-left to the bottom-right of the maze. If it is not possible to reach the destination, output -1.## sample
5 5
0 0 1 0 0
0 0 1 0 0
0 0 1 0 0
0 0 1 0 0
0 0 0 0 0
8