#K93967. Taco's Garden Path

    ID: 38537 Type: Default 1000ms 256MiB

Taco's Garden Path

Taco's Garden Path

In this problem, you are given a 2D grid representing a garden. Each cell in the grid contains either a 'G' (grass) or an 'R' (rock). Your task is to determine whether there exists a path from the top-left corner (cell (0, 0)) to the bottom-right corner (cell (M-1, N-1)) that goes only through cells containing 'G'. Movement is allowed in the four cardinal directions: up, down, left, and right.

Formally, given a grid of dimensions M×NM \times N, you need to check if there is a sequence of cells starting at (0,0)(0,0) and ending at (M1,N1)(M-1, N-1) such that for each consecutive cell (i,j)(i,j) in the sequence, the absolute difference in their row or column indices is 1, and every cell in the path satisfies grid[i][j] = 'G'.

inputFormat

The input is given via standard input (stdin). The first line contains two integers MM and NN, representing the number of rows and columns in the grid respectively. The following MM lines each contain NN characters separated by spaces, where each character is either 'G' or 'R'.

outputFormat

Output a single line to standard output (stdout) containing either "Yes" if there exists a valid path from the top-left to the bottom-right cell, or "No" otherwise.## sample

3 3
G G R
G R G
G G G
Yes