P26395 [AtCoder] Neue Spiel
NOI
题目描述

Problem Description

There is a board with a grid of $ N $ rows and $ N $ columns, and $N \times N$ tiles.

The edges of the squares facing the outside have slots for the tiles. That is, the top, bottom, left, and right edges of the board each have $ N $ slots, totaling $4 \times N$ slots. Each slot is numbered as follows:

  • Top edge slots: from left to right $ U1, U2, ..., UN $
  • Bottom edge slots: from left to right $ D1, D2, ..., DN $
  • Left edge slots: from top to bottom $ L1, L2, ..., LN $
  • Right edge slots: from top to bottom $ R1, R2, ..., RN $

Figure: Example of slot numbering

Tiles can be inserted into these slots. If a tile is inserted into a square that already contains a tile, the existing tile is pushed one square forward, and if that square also contains a tile, it is pushed forward similarly. However, tiles cannot be inserted if the pushed tiles would end up outside the board. For detailed examples of the behavior when inserting tiles, refer to the input/output example #1.

Snuke is trying to place one tile on each square by inserting the $N \times N$ tiles one by one through the slots. However, exactly $ U_i $ tiles must be inserted through slot $ Ui $, exactly $ D_i $ tiles through slot $ Di $, exactly $ L_i $ tiles through slot $ Li $, and exactly $ R_i $ tiles through slot $ Ri $. Determine if such an insertion method is possible. If it is, output the order of insertion.

Input Format

The input is given from the standard input in the following format:

$ N $ $ U_1 $ $ U_2 $ $ ... $ $ U_N $ $ D_1 $ $ D_2 $ $ ... $ $ D_N $ $ L_1 $ $ L_2 $ $ ... $ $ L_N $ $ R_1 $ $ R_2 $ $ ... $ $ R_N $

Output Format

If it is possible to insert the tiles so that each square contains one tile, output the slot numbers in the order they should be inserted, one per line. If it is not possible, output NO instead. If there are multiple possible orders of insertion, output any one of them.

Sample Input and Output

Sample Input #1

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

Sample Output #1

L1
L1
L1
L3
D1
R2
U3
R3
D2

Sample Input #2

2
2 0
2 0
0 0
0 0

Sample Output #2

NO

Notes/Hints

Constraints

  • $1 \leq N \leq 300$
  • $ U_i, D_i, L_i, R_i $ are integers greater than or equal to 0.
  • The sum of $ U_i, D_i, L_i, R_i $ is equal to $N \times N$.

Partial Points

  • If you solve the dataset satisfying $N \leq 40$, you will be awarded 2000 points.
  • If you solve the dataset without additional constraints, you will be awarded an additional 100 points.

Sample Explanation 1

You can insert the tiles as shown in the figure below. The arrows indicate the insertion points, the circles represent the tiles, and the numbers inside the circles indicate the order in which the tiles were inserted.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 0 0 1 1 1 0 3 0 1 0 1 1
样例输出
L1 L1 L1 L3 D1 R2 U3 R3 D2