#C10767. Path in a Parking Lot
Path in a Parking Lot
Path in a Parking Lot
You are given a rectangular parking lot represented as a grid with r
rows and c
columns. Each cell in the grid is one of the following characters:
.
: a free space where you can drive.#
: a wall that cannot be passed.C
: a parked car which acts as an obstacle.
Your task is to determine whether there exists a path from the top-left corner (cell at position (0,0)) to the bottom-right corner (cell at position (r-1, c-1)). You are only allowed to move in the four cardinal directions (up, down, left, right) and you can only traverse cells that are free (.
).
Note: For the purpose of this problem, you can assume the grid dimensions satisfy \(1 \le r, c \le 1000\).
inputFormat
The input is provided through standard input as follows:
- The first line contains two integers
r
andc
, the number of rows and columns respectively. - The next
r
lines each contain a string of lengthc
representing a row of the parking lot. The characters will be either.
,#
, orC
.
Example:
4 4 ...# .#.. .#C. ....
outputFormat
Output a single line to standard output containing YES
if a valid path exists from the top-left corner to the bottom-right corner, and NO
otherwise.
4 4
...#
.#..
.#C.
....
YES