#K86362. Robot Grid Navigation
Robot Grid Navigation
Robot Grid Navigation
You are given a grid with m rows and n columns. In this grid, several robots start at given positions and follow a sequence of instructions. Each instruction is one of the four moves: left (L), right (R), up (U), and down (D). As the robot executes instructions one by one, if it ever moves outside the grid boundaries, it is considered out‐of‐bounds.
Your task is to determine for each robot whether it stays within the grid throughout its entire sequence of moves. The grid boundaries are defined by row indices 1 to \(m\) and column indices 1 to \(n\).
Note: All moves are executed sequentially. If at any point the robot's position falls outside the valid range, output "YES" if it remained in bounds for all moves, otherwise output "NO".
inputFormat
The input is read from stdin and has the following format:
- The first line contains two integers \(m\) and \(n\) denoting the number of rows and columns of the grid.
- The second line contains an integer \(q\) representing the number of robots.
- Each of the next \(q\) lines contains two integers \(x\) and \(y\) followed by a string representing the sequence of instructions. \(x\) and \(y\) denote the starting row and column (respectively) of the robot.
outputFormat
For each robot, output a single line to stdout: "YES" if the robot completes all moves within the grid, and "NO" otherwise.
## sample5 5
3
1 1 RDU
2 2 LLR
3 3 DDDUU
YES
NO
NO
</p>