#P15695. [2018 KAIST RUN Spring] PuyoPuyo

[2018 KAIST RUN Spring] PuyoPuyo

题目描述

:::align{center}

Figure: Screenshot of PuyoPuyo game. This game uses 12×612 \times 6 grid. There are 44 kinds of color. :::

PuyoPuyo is a famous series video game made by Compile Co., Ltd.. First game was released in 1991. The company defunct at 2003, but

PuyoPuyo team is still making game in Sonic Team™ to this day, 2018.

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 below of the grid.
  • Each Puyo has a color.
  • There are KK kinds of color 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.
  • When you drop the Puyo, it each Puyo 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.
  • More than four Puyos that have same colors and shares an edge is called Group, and such groups are removed. This process is called Popping.
  • If dropping a Puyo pair makes two or more groups, it is popped simultaneously.
  • After group pops, remaining Puyos fall to another Puyo or the bottom of the grid. If it makes a new group, 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 R×CR \times C grid. Each grid is filled with certain color of Puyo or an empty grid. You should drop Puyo pair and derive a given grid. In the final state, every Puyo should be in the grid.

Fortunately, you can choose which color and place to drop.

输入格式

Input consists of R+1R + 1 lines.

First line contains three space-separated integers RR, CC and KK.

Next RR lines contain the final grid. Each line contains CC number of space-separated integers. Each color is represented by an integer 1 through KK. 0 means an empty grid.

A given final grid can be made by no more than 250 Puyo pair drops.

输出格式

In the first line, you have to print the number of Puyo pair DD.

In following DD 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 row 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 3
0 0 0 0
0 0 0 0
0 0 0 0
0 1 0 1
5
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:

:::align{center} :::

Constraints

  • 3K63 \le K \le 6
  • R=C=4R = C = 4 or R=C=20R = C = 20
  • D250D \le 250 (You have to use 250 or less Puyo pairs.)