#C9806. Robot Path in a Maze

    ID: 53940 Type: Default 1000ms 256MiB

Robot Path in a Maze

Robot Path in a Maze

You are given a maze represented as a 2D grid, where each cell is either open or blocked. An open cell is represented by 0 and a blocked cell by 1. The robot starts at the top-left corner (cell (0,0)) and its goal is to reach the bottom-right corner (cell (n-1,m-1)). The robot can move in four directions: up, down, left, and right.

Your task is to determine if there exists a path from the starting cell to the goal cell.

In mathematical terms, given a grid of size \(n \times m\), you must decide whether there exists a sequence of moves that leads from the cell \((0,0)\) to \((n-1,m-1)\), under the constraint that the robot can only move to adjacent cells (sharing a side) and only if they are open (i.e., equal to 0).

inputFormat

The first line of input contains two integers n and m — the number of rows and columns of the grid respectively.

Then follow n lines, each containing m space-separated integers (either 0 or 1) representing the grid.

You can assume that \(1 \leq n, m \leq 1000\).

outputFormat

Output a single line: True if the robot can reach the bottom-right cell, or False otherwise.

## sample
3 3
0 0 1
0 0 1
1 0 0
True