405138: GYM101806 P Puyo Puyo
Description
PuyoPuyo is a 2 player battle game. Each player plays by placing Puyo to grid. The detailed game rule is as follows:
- The game starts with an empty grid.
- Puyo is a round, slime-like object that falls from above to the bottom of the grid
- Each Puyo has a color.
- There are K kinds of colors of Puyo.
- Puyos are controlled as a pair (two Puyos).
- Puyo pair can be moved, dropped or rotated using a game controller.
- At the topmost part of the screen, Puyo pair can be moved horizontally, and can be rotated in horizontal or vertical direction.
- WWhen you drop the Puyo pair, each of the pair drops separately, until it reaches another Puyo or the bottom of the grid.
- You can place Puyo outside of the grid, but only over the grid.
- Four or more adjacent Puyos that have the same colors are called a Group, and such groups are removed. This process is called Popping.
- If dropping a Puyo pair makes two or more groups, they are popped simultaneously.
- After the groups pops, remaining Puyos fall to another Puyo or the bottom of the grid. If they make new groups, same procedure is repeated. This process is called Chain.
- During chains, you cannot place another Puyo pair.
Sonic Team™ requested your help to make PPAP (Puyo Puyo Algorithm for Printing). This will not be used in game software but will be used in special ceremonies.
You are given an R × C grid. Each cell of the grid contains a Puyo of a certain color or is empty. You should start from an empty grid and drop Puyo pairs to derive the given grid.
Fortunately, you can choose which color and place to drop.
InputFirst line contains three space-separated integers R, C and K. (R = C = 4 or R = C = 20, 3 ≤ K ≤ 6)
Next R lines contain the final grid. Each line contains C number of space-separated integers. Each color is represented by an integer 1 through K. 0 means an empty cell.
A given final grid can be made by no more than 250 Puyo pair drops.
OutputIn the first line, you have to print the number of Puyo pairs D. (D ≤ 250)
In following D lines, print four space-separated integers in each line.
- If you place Puyo pair horizontally, the first number is 0. If you place vertically, the first number is 1.
- Second number represents the column number of the left Puyo.
- Third number represents the color of left or upper Puyo of the pair.
- Fourth number represents the color of right or lower Puyo of the pair.
4 4 3Output
0 0 0 0
0 0 0 0
0 0 0 0
0 1 0 1
5Note
0 2 1 2
1 4 1 2
0 2 2 3
1 3 3 3
1 3 2 3
In this example, Puyos are dropped like following :
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0
0 0 0 0 -> 0 0 0 0 -> 0 0 0 0 -> 0 0 3 0 -> 0 0 3 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 3 0
0 0 0 0 0 0 0 1 0 2 3 1 0 2 3 1 0 2 3 1
0 1 2 0 0 1 2 2 0 1 2 2 0 1 2 2 0 1 2 2
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
-> 0 0 0 0 -> 0 0 0 0 -> 0 0 0 0 -> 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 2 0 1 0 2 2 1 0 0 0 1 0 0 0 0
0 1 2 2 0 1 2 2 0 1 0 0 0 1 0 1