#abc227h. H - Eat Them All

H - Eat Them All

Score : 600600 points

问题陈述

我们有一个具有 33 行(水平)和 33 列(垂直)的网格。令 (i,j)(i, j) 表示从上到下的第 ii 行以及从左数起的第 jj 列的方格。在方格 (i,j)(i, j) 中有 Ai,jA_{i,j} 罐猫粮。

Snuke 当前位于 (1,1)(1,1) 处。他将重复以下操作:

  • 在所在方格消耗一罐猫粮,然后向上、下、左或右移动到相邻的方格。

当所在方格中没有更多猫粮时,他将结束这个过程。

在该过程结束时,是否可能满足所有以下条件?如果可能,请展示一种实现这些条件的操作序列。

  • Snuke 位于 (1,1)(1,1) 处。
  • 每个方格上都没有剩余猫粮。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a grid with 33 horizontal rows and 33 vertical columns. Let (i,j)(i, j) denote the square at the ii-th row from the top and jj-th column from the left. (i,j)(i, j) contains Ai,jA_{i,j} cans of cat food.

Snuke is now on (1,1)(1,1). 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 (1,1)(1,1).
  • There is no more can on every square.

Constraints

  • 1Ai,j1001 \leq A_{i,j} \leq 100
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

A1,1A_{1,1} A1,2A_{1,2} A1,3A_{1,3}

A2,1A_{2,1} A2,2A_{2,2} A2,3A_{2,3}

A3,1A_{3,1} A3,2A_{3,2} A3,3A_{3,3}

Output

If it is impossible that the conditions are satisfied, print NO.

If it is possible, print a string SS consisting of L, R, U, D. The ii-th character of SS should represent the ii-th action of Snuke, where L, R, U, D means moving one square left, right, up, down, respectively.

Sample Input 1

1 1 1
1 1 1
1 2 1

Sample Output 1

DDRUDRUULL

Note that Snuke must be back on (1,1)(1, 1) in the end.

There are also other correct outputs, such as RRDDLUDLUU.

Sample Input 2

2 4 2
2 1 1
1 1 2

Sample Output 2

NO

It is impossible to achieve the objective, so print NO.

Sample Input 3

2 2 3
2 1 2
1 3 2

Sample Output 3

DUDDRUDRLRUULRDULL

update @ 2024/3/10 09:57:50