题目描述
Problem Description
There is a grid with $ H $ rows and $ W $ columns. The cell at the $ i $-th row and $ j $-th column is denoted as cell $(i,\ j)$.
Cell $(i,\ j)$ is an empty cell if $C_{i,\ j}$ is ., and it is not an empty cell if $C_{i,\ j}$ is #.
Takahashi is currently at cell $(S_i,\ S_j)$ and will follow the rules below in order for $i = 1,\ 2,\ \ldots,\ |X|$.
- If the $ i $-th character of $ X $ is
L, and if the cell to the left of the cell where Takahashi is currently located exists and is an empty cell, he moves to that cell. Otherwise, he stays in the current cell. - If the $ i $-th character of $ X $ is
R, and if the cell to the right of the cell where Takahashi is currently located exists and is an empty cell, he moves to that cell. Otherwise, he stays in the current cell. - If the $ i $-th character of $ X $ is
U, and if the cell above the cell where Takahashi is currently located exists and is an empty cell, he moves to that cell. Otherwise, he stays in the current cell. - If the $ i $-th character of $ X $ is
D, and if the cell below the cell where Takahashi is currently located exists and is an empty cell, he moves to that cell. Otherwise, he stays in the current cell.
Output the cell where Takahashi is after completing the series of actions.
Input Format
The input is given from the standard input in the following format:
$ H $ $ W $ $ S_i $ $ S_j $ $ C_{1,\ 1} $$ C_{1,\ 2} $$ \ldots $$ C_{1,\ W} $ $ C_{2,\ 1} $$ C_{2,\ 2} $$ \ldots $$ C_{2,\ W} $ $ \vdots $ $ C_{H,\ 1} $$ C_{H,\ 2} $$ \ldots $$ C_{H,\ W} $ $ X $
Output Format
Let the cell where Takahashi is after completing the series of actions be cell $(x,\ y)$. Output $ x $ and $ y $ in this order, separated by a space.
Sample Input and Output
Sample Input #1
2 3
2 1
.#.
...
ULDRU
Sample Output #1
2 2
Sample Input #2
4 4
4 2
....
.#..
...#
....
DUUUURULRD
Sample Output #2
2 4
Sample Input #3
6 6
1 1
.#####
######
######
######
######
######
RURLDLULLRULRDL
Sample Output #3
1 1
Notes/Hints
Constraints
- $1 \leq H,\ W \leq 50$
- $1 \leq S_i \leq H$
- $1 \leq S_j \leq W$
- $H,\ W,\ S_i,\ S_j$ are integers
- $C_{i,\ j}$ is either
.or# - $C_{S_i,\ S_j} =$
. - $ X $ is a string of length between $ 1 $ and $ 50 $ inclusive, consisting of
L,R,U,D
Sample Explanation 1
Takahashi starts at cell $(2,\ 1)$. His series of actions is as follows:
- The first character of $ X $ is U, and the cell above $(2,\ 1)$ exists and is an empty cell, so he moves to cell $(1,\ 1)$.
- The second character of $ X $ is L, and there is no cell to the left of $(1,\ 1)$, so he stays at $(1,\ 1)$.
- The third character of $ X $ is D, and the cell below $(1,\ 1)$ exists and is an empty cell, so he moves to cell $(2,\ 1)$.
- The fourth character of $ X $ is R, and the cell to the right of $(2,\ 1)$ exists and is an empty cell, so he moves to cell $(2,\ 2)$.
- The fifth character of $ X $ is U, and the cell above $(2,\ 2)$ exists but is not an empty cell, so he stays at $(2,\ 2)$.
Therefore, after completing the series of actions, Takahashi is at cell $(2,\ 2)$.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分