#C10353. Spaceship Navigation in a Debris Field
Spaceship Navigation in a Debris Field
Spaceship Navigation in a Debris Field
You are given a 2D grid of size (n \times m), where each cell is either empty (denoted by '.') or contains debris (denoted by 'D'). The spaceship starts at the top-left corner (cell ((0,0))) and needs to reach the bottom-right corner (cell ((n-1,m-1))). The spaceship can move in the four cardinal directions: up, down, left, and right. It cannot move into a cell that contains debris. Determine whether there exists a valid path from the starting cell to the target cell. Note that both the starting and ending cells must be free of debris.
inputFormat
The first line contains two integers (n) and (m) ((1 \leq n, m \leq 1000)), representing the number of rows and columns respectively. Each of the next (n) lines contains a string of (m) characters, where each character is either '.' (an empty cell) or 'D' (a cell with debris).
outputFormat
Output a single line containing either "YES" if a valid path exists from cell ((0,0)) to cell ((n-1,m-1)), or "NO" if no such path exists.## sample
5 5
...D.
DD.D.
....D
D.DD.
.....
YES