#K71022. Find Final Coordinates on a Grid
Find Final Coordinates on a Grid
Find Final Coordinates on a Grid
You are given a grid with dimensions \(m\) and \(n\). Starting from the coordinate \((0, 0)\), you are given a sequence of moves. The moves are represented by the following characters:
- R: move right (increase the \(y\)-coordinate by 1)
- D: move down (increase the \(x\)-coordinate by 1)
- X: move diagonally (increase both \(x\) and \(y\)-coordinates by 1)
After executing each move, the coordinates are capped at the grid boundaries, meaning that \(x \leq m\) and \(y \leq n\). Your task is to determine the final coordinates after following the entire sequence of moves.
inputFormat
The input is read from standard input (stdin). It consists of two lines:
- The first line contains two space-separated integers \(m\) and \(n\) indicating the grid dimensions.
- The second line contains a string representing the sequence of moves.
Note: The grid is 0-indexed starting at \((0,0)\), and moves that would take you beyond the grid limits are capped.
outputFormat
Output the final coordinates as two space-separated integers \(x\) and \(y\), where \(x\) is the final row (vertical coordinate) and \(y\) is the final column (horizontal coordinate).
## sample2 2
RRDD
2 2