luogu#P9195. [JOI Open 2016] JOIRIS
[JOI Open 2016] JOIRIS
Background
Translated from JOI Open 2016 T1 "JOIRIS".
Problem Description
The play area of JOIRIS is called the "Well". It is a rectangular grid with width and sufficiently large height. The cell in the -th column from the left and the -th row from the bottom is denoted by . During the game, each cell either contains a block or is empty.
At the beginning, in column , and only in that column, the cells contain blocks.
Next, dominoes of size fall one by one, and the player must place them in order. Each placement is performed as follows:
The player first chooses whether to place the domino horizontally or vertically.
- If the player chooses vertical placement, they must additionally choose an integer (). The domino will fall to the row just above the topmost block in column . If there is no block in column , the domino will fall to the bottom of the well.
- If the player chooses horizontal placement, they must additionally choose an integer (). The domino will fall to the row just above the highest topmost block among columns through . If there are no blocks in columns through , the domino will fall to the bottom of the well.
After each domino stops falling, the system checks the well row by row from the bottom upward. If a row is completely filled with blocks, all blocks in that row disappear, and all blocks above it move down by cell.
Then it checks whether there are any blocks left in the well. If there are no blocks, the game ends and the player wins. Otherwise, the player starts placing the next domino.
It is guaranteed that initially the bottom row is not completely filled with blocks. Determine whether the player can win. If it is possible, output one valid strategy.
Input Format
The input consists of lines.
The first line contains two integers .
In the next lines, the -th line () contains one integer .
Output Format
If the player cannot win, output one line containing .
Otherwise, output lines, where is the number of moves needed to eliminate all blocks:
The first line contains an integer . The next -th line () describes your strategy.
- If the -th falling domino is placed vertically, output two integers. The first integer is , and the second integer indicates the position where the player places the piece (as described above).
- If the -th falling domino is placed horizontally, output two integers. The first integer is , and the second integer indicates the position where the player places the piece (as described above).
4 2
1
0
1
2
4
2 2
1 1
2 3
1 2
3 2
2
0
1
3
1 2
1 3
2 1
2 2
0
1
-1
5 3
1
0
1
0
1
9
1 4
1 5
2 1
2 1
2 2
1 1
1 2
2 3
2 3
Hint
Explanation for Sample 1

Constraints and Notes
This problem uses bundled testdata.
For all testdata, , , .
- Subtask 1 (15 points): and is odd.
- Subtask 2 (15 points): and is even.
- Subtask 3 (15 points): divides .
- Subtask 4 (55 points): No additional constraints.
Translated by ChatGPT 5