#C859. Robot's Path in a Grid
Robot's Path in a Grid
Robot's Path in a Grid
In this problem, you are given a grid of size (n \times m) where each cell is either walkable (denoted by 'O') or blocked (denoted by 'X'). The robot starts at the top-left corner (0,0) and needs to reach the bottom-right corner ((n-1,m-1)) by only moving right or down. Your task is to find a valid path if it exists. If there is a valid path, output each coordinate of the path on a separate line in the format row col
. If no such path exists, output a single line with -1.
Note: The only allowed moves are right ((0,1)) and down ((1,0)).
inputFormat
The first line contains two integers (n) and (m) representing the number of rows and columns of the grid. This is followed by (n) lines, each containing (m) characters separated by spaces. Each character is either 'O' (denoting an open cell) or 'X' (denoting an obstacle).
outputFormat
If a valid path is found, output the coordinates of the path from the start to the end in order, with each coordinate printed on a new line in the format: row col
. If no valid path exists, output a single line with -1.## sample
3 3
O O X
O X O
O O O
0 0
1 0
2 0
2 1
2 2
</p>