

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
縦 行横 列に区切られたマス目があり、上から 番目、左から 列目のマスをマス と呼びます。
マス には 枚のコインが置かれています。
あなたは以下の操作を何度でも行うことができます。
操作: まだ選んだことのないマスのうち 枚以上のコインが置かれているマスを つ選び、そのマスに置かれているコインのうち 枚を上下左右に隣接するいずれかのマスに移動する
偶数枚のコインが置かれたマスの数を最大化してください。
制約
- 入力はすべて整数である
入力
入力は以下の形式で標準入力から与えられる。
出力
偶数枚のコインが置かれたマスの数が最大となるような操作の列を次の形式で出力せよ。
すなわち、 行目には操作の回数を表す 以上 以下の整数 を出力せよ。
() 行目には 回目の操作を表す整数 ( かつ ) を出力せよ。 ただし、これはマス にあるコインのうち 枚を上下左右に隣接するマス に移動させる操作を表す。
問題文中の操作でないような操作が与えられた場合や、出力の形式が正しくない場合には Wrong Answer となるので注意せよ。
入力例 1Copy
2 3 1 2 3 0 1 1
出力例 1Copy
3 2 2 2 3 1 1 1 2 1 3 1 2
次のように操作を行えば、全てのマスに置かれたコインの数を偶数にできます。
- マス に置かれているコインのうち 枚をマス に移動します
- マス に置かれているコインのうち 枚をマス に移動します
- マス に置かれているコインのうち 枚をマス に移動します
入力例 2Copy
3 2 1 0 2 1 1 0
出力例 2Copy
3 1 1 1 2 1 2 2 2 3 1 3 2
入力例 3Copy
1 5 9 9 9 9 9
出力例 3Copy
2 1 1 1 2 1 3 1 4
Score : points
Problem Statement
There is a grid of square cells with horizontal rows and vertical columns. The cell at the -th row and the -th column will be denoted as Cell .
In Cell , coins are placed.
You can perform the following operation any number of times:
Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell.
Maximize the number of cells containing an even number of coins.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format:
That is, in the first line, print an integer between and (inclusive), representing the number of operations.
In the -th line (), print four integers and ( and ), representing the -th operation. These four integers represents the operation of moving one of the coins placed in Cell to a vertically or horizontally adjacent cell, .
Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in Wrong Answer.
Sample Input 1Copy
2 3 1 2 3 0 1 1
Sample Output 1Copy
3 2 2 2 3 1 1 1 2 1 3 1 2
Every cell contains an even number of coins after the following sequence of operations:
- Move the coin in Cell to Cell .
- Move the coin in Cell to Cell .
- Move one of the coins in Cell to Cell .
Sample Input 2Copy
3 2 1 0 2 1 1 0
Sample Output 2Copy
3 1 1 1 2 1 2 2 2 3 1 3 2
Sample Input 3Copy
1 5 9 9 9 9 9
Sample Output 3Copy
2 1 1 1 2 1 3 1 4