#abc364b. B - Grid Walk

B - Grid Walk

Score : 200200 points

问题陈述

有一个 HHWW 列的网格。用 (i,j)(i, j) 表示从顶部数第 ii 行,从左边数第 jj 列的单元格。

如果 Ci,jC_{i, j}.,则单元格 (i,j)(i, j) 是空的;如果 Ci,jC_{i, j}#,则单元格不为空。

高桥目前位于单元格 (Si,Sj)(S_i, S_j),他将按照以下规则进行操作,对于 i=1,2,,Xi = 1, 2, \ldots, |X| 依次执行。

  • 如果 XX 的第 ii 个字符是 L,并且他当前单元格左侧的单元格存在且为空,则他向左移动到该单元格。否则,他留在当前单元格。
  • 如果 XX 的第 ii 个字符是 R,并且他当前单元格右侧的单元格存在且为空,则他向右移动到该单元格。否则,他留在当前单元格。
  • 如果 XX 的第 ii 个字符是 U,并且他当前单元格上方的单元格存在且为空,则他向上移动到该单元格。否则,他留在当前单元格。
  • 如果 XX 的第 ii 个字符是 D,并且他当前单元格下方的单元格存在且为空,则他向下移动到该单元格。否则,他留在当前单元格。

打印出他完成一系列操作后的单元格位置。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

There is a grid with HH rows and WW columns. Let (i,j)(i, j) denote the cell at the ii-th row from the top and jj-th column from the left.

Cell (i,j)(i, j) is empty if Ci,jC_{i, j} is ., and not empty if Ci,jC_{i, j} is #.

Takahashi is currently at cell (Si,Sj)(S_i, S_j), and he will act according to the following rules for i=1,2,,Xi = 1, 2, \ldots, |X| in order.

  • If the ii-th character of XX is L, and the cell to the left of his current cell exists and is empty, he moves to the cell to the left. Otherwise, he stays in the current cell.
  • If the ii-th character of XX is R, and the cell to the right of his current cell exists and is empty, he moves to the cell to the right. Otherwise, he stays in the current cell.
  • If the ii-th character of XX is U, and the cell above his current cell exists and is empty, he moves to the cell above. Otherwise, he stays in the current cell.
  • If the ii-th character of XX is D, and the cell below his current cell exists and is empty, he moves to the cell below. Otherwise, he stays in the current cell.

Print the cell where he is after completing the series of actions.

Constraints

  • 1H,W501 \leq H, W \leq 50
  • 1SiH1 \leq S_i \leq H
  • 1SjW1 \leq S_j \leq W
  • H,W,Si,SjH, W, S_i, S_j are integers.
  • Ci,jC_{i, j} is . or #.
  • CSi,Sj=C_{S_i, S_j} = .
  • XX is a string of length between 11 and 5050, inclusive, consisting of L, R, U, D.

Input

The input is given from Standard Input in the following format:

HH WW

SiS_i SjS_j

C1,1C_{1, 1}C1,2C_{1, 2}\ldotsC1,WC_{1, W}

C2,1C_{2, 1}C2,2C_{2, 2}\ldotsC2,WC_{2, W}

\vdots

CH,1C_{H, 1}CH,2C_{H, 2}\ldotsCH,WC_{H, W}

XX

Output

Let (x,y)(x, y) be the cell where Takahashi is after completing the series of actions. Print xx and yy, separated by a space.

Sample Input 1

2 3
2 1
.#.
...
ULDRU

Sample Output 1

2 2

Takahashi starts at cell (2,1)(2, 1). His series of actions are as follows:

  • The 1st character of XX is U, and the cell above (2,1)(2, 1) exists and is an empty cell, so he moves to the cell above, which is (1,1)(1, 1).
  • The 2nd character of XX is L, and the cell to the left of (1,1)(1, 1) does not exist, so he stays at (1,1)(1, 1).
  • The 3rd character of XX is D, and the cell below (1,1)(1, 1) exists and is an empty cell, so he moves to the cell below, which is (2,1)(2, 1).
  • The 4th character of XX is R, and the cell to the right of (2,1)(2, 1) exists and is an empty cell, so he moves to the cell to the right, which is (2,2)(2, 2).
  • The 5th character of XX is U, and the cell above (2,2)(2, 2) exists but is not an empty cell, so he stays at (2,2)(2, 2).

Therefore, after completing the series of actions, he is at cell (2,2)(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