Game with Chips

题意翻译

## 题目描述 Petya 有一个大小为 $n×m$ 的矩形版。一开始,在板子上有 $k$ 个芯片,第 $i$ 个芯片位置位于第 $sx$ 行与第 $sy$ 列的相交点上。 在一次操作中, Petya 可以把所有的芯片向左、向右、向下或者向上移动一格。 如果芯片在 $(x, y)$ 格中,则在操作之后: - 往左:坐标为 $(x, y - 1)$; - 往右:坐标为 $(x, y + 1)$; - 往下:坐标为 $(x + 1, y)$; - 往上:坐标为 $(x - 1, y)$; 如果现在芯片在版的边缘上,然而 Petya 将其移向边缘,那么芯片的位置保持不变。 对于每一个芯片, Petya 选择了他应该到达的位置。注意:芯片不须在这个地方停下来。 由于 Petya 时间不多, 总操作数不能超过 $2nm$。 你需要求出 Petya 应该做的操作:在不超过 $2nm$ 的操作里让每个芯片走过 Petya 选定的位置一遍。或者说明是不可能达到目的的。 ## 输入格式 第一行三个整数 $n,m,k$($1 \le n,m,k \le 200$),分别表示矩形板的长,矩形板的宽和芯片的个数。 接下来的 $k$ 行每行两个整数 $ sx_i, sy_i$ ($1 \le sx_i \le n, 1 \le sy_i \le m$),表示第 $i$ 个芯片的初始位置。 再接下来的 $k$ 行每行两个整数 $ fx_i, fy_i$ ($1 \le fx_i \le n, 1 \le fy_i \le m$),表示第 $i$ 个芯片须达到的位置。 ## 输出格式 输出第一行一个整数,表示能达到目的的操作次数(不需要最小)。 在第二行输出一个序列,用 "L、R、D、U" 分别表示 "左、右、下、上" 。 若无解,则输出 $ -1 $ 。

题目描述

Petya has a rectangular Board of size $ n \times m $ . Initially, $ k $ chips are placed on the board, $ i $ -th chip is located in the cell at the intersection of $ sx_i $ -th row and $ sy_i $ -th column. In one action, Petya can move all the chips to the left, right, down or up by $ 1 $ cell. If the chip was in the $ (x, y) $ cell, then after the operation: - left, its coordinates will be $ (x, y - 1) $ ; - right, its coordinates will be $ (x, y + 1) $ ; - down, its coordinates will be $ (x + 1, y) $ ; - up, its coordinates will be $ (x - 1, y) $ . If the chip is located by the wall of the board, and the action chosen by Petya moves it towards the wall, then the chip remains in its current position. Note that several chips can be located in the same cell. For each chip, Petya chose the position which it should visit. Note that it's not necessary for a chip to end up in this position. Since Petya does not have a lot of free time, he is ready to do no more than $ 2nm $ actions. You have to find out what actions Petya should do so that each chip visits the position that Petya selected for it at least once. Or determine that it is not possible to do this in $ 2nm $ actions.

输入输出格式

输入格式


The first line contains three integers $ n, m, k $ ( $ 1 \le n, m, k \le 200 $ ) — the number of rows and columns of the board and the number of chips, respectively. The next $ k $ lines contains two integers each $ sx_i, sy_i $ ( $ 1 \le sx_i \le n, 1 \le sy_i \le m $ ) — the starting position of the $ i $ -th chip. The next $ k $ lines contains two integers each $ fx_i, fy_i $ ( $ 1 \le fx_i \le n, 1 \le fy_i \le m $ ) — the position that the $ i $ -chip should visit at least once.

输出格式


In the first line print the number of operations so that each chip visits the position that Petya selected for it at least once. In the second line output the sequence of operations. To indicate operations left, right, down, and up, use the characters $ L, R, D, U $ respectively. If the required sequence does not exist, print -1 in the single line.

输入输出样例

输入样例 #1

3 3 2
1 2
2 1
3 3
3 2

输出样例 #1

3
DRD

输入样例 #2

5 4 3
3 4
3 1
3 3
5 3
1 3
1 4

输出样例 #2

9
DDLUUUURR