QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#358. 积木

الإحصائيات

有一块 $n$ 行 $m$ 列的网格板,$n, m$ 都是奇数。网格上平铺着一些 $1\times2$ 的积木。积木可以旋转,不能重叠。这些积木共有 $\frac{nm-1}{2}$ 块,也就是说,网格板上只有一格的空位。

你可以做两种操作:

  1. 将一块与空白格相邻(指有公共边)的积木旋转 $90^\circ$ 到空白格中;
  2. 将一块与空白格相邻的积木平移至空白格中。

如图所示(被移动的积木颜色较浅):

problem_358_1.webp

请你用以上两种操作将给定的网格板变换为指定的状态。

输入格式

第一行两个正奇数 $n, m$,分别表示网格的行数和列数。

接下来 $n$ 行,每行 $m$ 个字符,描述网格板的初始状态:

  • < 表示这个格子是一块积木的左半部分;
  • > 表示这个格子是一块积木的右半部分;
  • n 表示这个格子是一块积木的上半部分;
  • u 表示这个格子是一块积木的下半部分;
  • o 表示这个格子是空的。

接下来另外 $n$ 行,每行 $m$ 个字符,描述你需要将网格板变成的目标状态,格式同上。

输出格式

你需要输出一个字符串,按顺序表示你的操作:

  • L 表示你移动了空白格左侧的积木;
  • R 表示你移动了空白格右侧的积木;
  • U 表示你移动了空白格上方的积木;
  • D 表示你移动了空白格下方的积木。

当然,没有操作的话输出空串就好了。

样例数据

样例 1 输入

3 3
nnn
uuu
o<>
<>n
<>u
<>o

样例 1 输出

URLR

样例 2 输入

5 5
n<><>
un<>n
nuonu
u<>un
<><>u
<><>o
<><>n
<><>u
<><>n
<><>u

样例 2 输出

RLLRLRR

样例 2 解释

初始状态和目标状态分别是题图中的网格 $A,B$。

子任务

你输出的操作序列长度不能超过 $8\times10^6$。

对于所有数据,$1\le n, m\le 2000$。

  • 对于 $10\%$ 的数据,$n,m\le 3$;
  • 对于另外 $10\%$ 的数据,$n,m \le 5$;
  • 对于另外 $20\%$ 的数据,$m=3$;
  • 对于另外 $20\%$ 的数据,$n,m \le 50$;
  • 对于另外 $20\%$ 的数据,$n,m \le 200$;
  • 对于余下 $20\%$ 的数据,无特殊限制。
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.