QOJ.ac

QOJ

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

#8355. T3

統計

小 T 有一张 $n\times n$ 的棋盘和很多硬币。他想把硬币都放到棋盘上,使得每个格子上恰好有一枚硬币。 记棋盘第一行的上方从左到右的位置依次为 $\text{U}1,\text{U}2,\cdots,\text{U}n$,最后一行下方从左到右的位置依次为 $\text{D}1,\text{D}2,\cdots,\text{D}n$。类似地,记第一列左边和最后一列右边从上到下的位置依次分别为 $\text{L}1,\text{L}2,\cdots,\text{L}n$ 与 $\text{R}1,\text{R}2,\cdots,\text{R}n$。

problem_8355_1.png

每次操作,小 T 会将一枚硬币放在这些在棋盘外面且与某个格子相邻的位置,之后按照往棋盘内的方向推硬币,直到该枚硬币恰好位于格子内为止。若格子上已经有另外一枚硬币,则那枚硬币也会被往里推一个格子。如果有硬币被推出棋盘外则视为失败。例如,下图是在 $3\times 3$ 的棋盘上进行的 $9$ 次合法操作。

problem_8355_2.png

小 T 觉得这样推硬币还是太没意思了。于是他对每个棋盘外面的位置 $\text{U}i,\text{D}i,\text{L}i,\text{R}i$ 都分别写上了数 $U_i,D_i,L_i,R_i$,表示在这个位置进行操作的次数。但在写完数之后,小 T 发现他并不能很快找出一组合法的方案,你能帮他找到吗?

输入格式

第一行一个整数 $n$,表示棋盘大小。

第二行 $n$ 个整数 $U_i$,表示位置 $\text{U}i$ 的操作次数。

第三行 $n$ 个整数 $D_i$,表示位置 $\text{D}i$ 的操作次数。

第四行 $n$ 个整数 $L_i$,表示位置 $\text{L}i$ 的操作次数。

第五行 $n$ 个整数 $R_i$,表示位置 $\text{R}i$ 的操作次数。

输出格式

如果无解,输出 NO。 否则输出 $n^2$ 行,每行形如 $\text{U}i,\text{D}i,\text{L}i$ 或 $\text{R}i$,表示该次操作的位置。

样例输入 1

3
0 0 1
1 1 0
3 0 1
0 1 1

样例输出 1

L1
L1
L1
L3
D1
R2
U3
R3
D2

样例输入 2

2
3 0
0 0
0 1
0 0

样例输出 2

NO

样例解释

样例 $1$ 即为题面中所给图片。

样例 $2$ 中 $U_1=3$,显然不可能构造出合法方案。

数据范围

对于所有数据,$1\leq n\leq 300$,$0\leq U_i,D_i,L_i,R_i$,$\sum \left(U_i+D_i+L_i+R_i\right)=n^2$。

子任务 $1$($11$ 分):$n\leq 3$。

子任务 $2$($15$ 分):$D_i=R_i=0$。

子任务 $3$($19$ 分):$D_i=0$。

子任务 $4$($25$ 分):$n\leq 40$。

子任务 $5$($30$ 分):无特殊限制。

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.