No.2411 Reverse Directions
タグ : / 解いたユーザー数 62
作問者 : 👑
hamamu
hari64
Problem Statement
There is a grid with $H$ rows and $W$ columns. The cell in the $i$-th row from the top and the $j$-th column from the left is denoted by cell $(i, j)$. Spikes are placed on some of the cells.
The state of the grid is given by strings $S_1, S_2, \dots, S_H$. If $S_{i, j}$ is #, there is a spike on cell $(i, j)$; if it is ., there is no spike on it.
Alice is on the grid. Alice can move from her current cell to a cell adjacent to it vertically or horizontally.
However, she cannot move to a cell with a spike or move outside the grid.
Alice is initially on cell $(1,1)$. Her goal is to be on cell $(H, W)$ after making exactly $K$ moves (she may pass through cell $(H, W)$ during earlier moves).
Alice decides in advance which direction to move in on each move (her movement plan) and tells it to Bob.
Now, before Alice tells Bob her movement plan, Bob, who wants to prevent Alice from reaching cell $(H, W)$, has made the following declaration.
- Declaration: The directions of Alice's moves from the $L$-th move through the $R$-th move will be reversed. Specifically, if the direction Alice decided on for such a move is up, down, left, or right, she must instead move down, up, right, or left on that move, respectively. Even for the reversed moves, moving to a cell with a spike or outside the grid is not allowed.
However, Bob does not necessarily carry out the Declaration. Therefore, Alice must use a movement plan with which she can reach cell $(H, W)$ in exactly $K$ moves whether or not Bob carries out the Declaration.
Determine whether such a movement plan exists, and if it does, show one.
Constraints
- $H, W, K, L, R$ are integers.
- $3 \leq H, W \leq 500$
- $4 \leq K \leq 5 \times 10^5$
- $1 \leq L \leq R \leq K$
- $S_i$ is a string of length $W$ consisting of
.and#. - $S_{1,1} =$
. - $S_{H,W} =$
.
Input
The input is given from Standard Input in the following format.
$H$ $W$ $K$ $L$ $R$ $S_1$ $S_2$ $\vdots$ $S_H$
Output
If no movement plan satisfying the conditions exists, print No. If one exists, print it in the following format.
Yes $T$
Here, $T$ is a string of length $K$ consisting of L, R, U, D, where $T_i$ being L, R, U, D means that the direction of the $i$-th move is left, right, up, down, respectively.
Sample
Sample 1
Input
3 3 8 3 6 ..# ... #..
Output
Yes RDRDLUDR
If Bob carries out the declaration, Alice's movement becomes RDLURDDR, and she can reach cell $(3, 3)$ in exactly $8$ moves.
On the other hand, if Bob does not carry out the declaration, Alice's movement is RDRDLUDR, and she can likewise reach cell $(3, 3)$ in exactly $8$ moves.
Sample 2
Input
4 4 2013 8 12 .... ..#. .... #...
Output
No
No matter what movement plan she uses, Alice cannot reach cell $(4, 4)$ in exactly $2013$ moves.
Sample 3
Input
4 4 14 7 8 .... ##.. ..## ....
Output
No
Alice cannot even reach cell $(4, 4)$ in the first place.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。