atcoder#ABC227H. [ABC227H] Eat Them All
[ABC227H] Eat Them All
Score : points
Problem Statement
We have a grid with horizontal rows and vertical columns. Let denote the square at the -th row from the top and -th column from the left. contains cans of cat food.
Snuke is now on . He will repeat the following action.
- Consume one can on the square he is on, and move up, down, left, or right to an adjacent square.
When there is no more can on the square he is on, he will end this process.
Is it possible that all of the conditions below are satisfied at the end of the process? If it is possible, show one sequence of actions that make it happen.
- Snuke is at .
- There is no more can on every square.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If it is impossible that the conditions are satisfied, print NO
.
If it is possible, print a string consisting of L
, R
, U
, D
. The -th character of should represent the -th action of Snuke, where L
, R
, U
, D
means moving one square left, right, up, down, respectively.
1 1 1
1 1 1
1 2 1
DDRUDRUULL
Note that Snuke must be back on in the end.
There are also other correct outputs, such as RRDDLUDLUU
.
2 4 2
2 1 1
1 1 2
NO
It is impossible to achieve the objective, so print NO
.
2 2 3
2 1 2
1 3 2
DUDDRUDRLRUULRDULL