#C2480. Taco: Reachability in a Grid
Taco: Reachability in a Grid
Taco: Reachability in a Grid
You are given a grid of size \(n \times m\) consisting of characters 'L' (land) and 'W' (water). Starting from the top-left corner \((1,1)\), you need to determine if it is possible to reach the bottom-right corner \((n,m)\) by moving only in the four cardinal directions (up, down, left, right) through cells marked with 'L'. Movement through any cell marked with 'W' is prohibited.
Input Format: The first line contains two integers \(n\) and \(m\) separated by a space, representing the number of rows and columns respectively. This is followed by \(n\) lines, each containing a string of length \(m\) representing the grid.
Output Format: Print YES
if the bottom-right corner is reachable from the top-left corner; otherwise, print NO
.
Note: The grid indices are 1-indexed in the description, but input processing should be done accordingly.
inputFormat
The input is read from stdin and is structured as follows:
n m row1 row2 ... rown
Where:
n
andm
are integers denoting the number of rows and columns.- Each of the next
n
lines contains a string ofm
characters, each being either 'L' or 'W'.
outputFormat
The output is written to stdout. It should be a single line containing either YES
or NO
, indicating whether the bottom-right cell is reachable from the top-left cell.
3 3
LLL
LLL
LLL
YES