#C4902. Path Existence in a Grid (Right and Down Moves Only)

    ID: 48492 Type: Default 1000ms 256MiB

Path Existence in a Grid (Right and Down Moves Only)

Path Existence in a Grid (Right and Down Moves Only)

You are given an n x m grid consisting of characters '.' (open cell) and '#' (blocked cell). Starting from the top-left cell (1,1) and only being allowed to move either right or down, your task is to determine whether there exists a path to reach the bottom-right cell (n, m).

If there is a valid path, output YES; otherwise, output NO. Note that the only allowed moves are to the right (i.e. from cell \((i, j)\) to \((i, j+1)\)) or downwards (i.e. from \((i, j)\) to \((i+1, j)\)).

Input Format: The first line contains two integers, \(n\) and \(m\), denoting the number of rows and columns. Each of the following \(n\) lines contains a string of length \(m\) representing the row of the grid.

Output Format: A single line containing YES if a valid path exists, or NO otherwise.

inputFormat

The input is given via stdin with the following format:

  • The first line contains two integers \(n\) and \(m\) \( (1 \leq n, m \leq 1000) \), the number of rows and columns of the grid.
  • The next \(n\) lines each contain a string of \(m\) characters where each character is either '.' (open cell) or '#' (blocked cell).

outputFormat

Print a single line to stdout containing either YES if there is a path from the top-left cell to the bottom-right cell using only right and down moves, or NO if no such path exists.

## sample
4 4
.#..
..#.
#...
.#..
YES

</p>