CF1772F.Copy of a Copy of a Copy

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

It all started with a black-and-white picture, that can be represented as an n×mn \times m matrix such that all its elements are either 00 or 11 . The rows are numbered from 11 to nn , the columns are numbered from 11 to mm .

Several operations were performed on the picture (possibly, zero), each of one of the two kinds:

  • choose a cell such that it's not on the border (neither row 11 or nn , nor column 11 or mm ) and it's surrounded by four cells of the opposite color (four zeros if it's a one and vice versa) and paint it the opposite color itself;
  • make a copy of the current picture.

Note that the order of operations could be arbitrary, they were not necessarily alternating.

You are presented with the outcome: all kk copies that were made. Additionally, you are given the initial picture. However, all k+1k+1 pictures are shuffled.

Restore the sequence of the operations. If there are multiple answers, print any of them. The tests are constructed from the real sequence of operations, i. e. at least one answer always exists.

输入格式

The first line contains three integers n,mn, m and kk ( 3n,m303 \le n, m \le 30 ; 0k1000 \le k \le 100 ) — the number of rows and columns of the pictures and the number of copies made, respectively.

Then k+1k+1 pictures follow — kk copies and the initial picture. Their order is arbitrary.

Each picture consists of nn lines, each consisting of mm characters, each character is either 00 or 11 . There is an empty line before each picture.

输出格式

In the first line, print a single integer — the index of the initial picture. The pictures are numbered from 11 to k+1k+1 in the order they appear in the input.

In the second line, print a single integer qq — the number of operations.

Each of the next qq lines should contain an operation. The operations should be listed in order they were applied. Each operation is one of two types:

  • 11 xx yy — recolor a cell (x,y)(x, y) (the yy -th cell in the xx -th row, it should not be on the border and it should be surrounded by four cells of opposite color to itself);
  • 22 ii — make a copy of the current picture and assign it index ii (picture with index the ii should be equal to the current picture).

Each index from 11 to k+1k+1 should appear in the output exactly once — one of them is the index of the initial picture, the remaining kk are arguments of the operations of the second kind.

If there are multiple answers, print any of them. The tests are constructed from the real sequence of operations, i. e. at least one answer always exists.

输入输出样例

  • 输入#1

    3 3 1
    
    010
    111
    010
    
    010
    101
    010

    输出#1

    2
    2
    1 2 2
    2 1
  • 输入#2

    4 5 3
    
    00000
    01000
    11100
    01000
    
    00000
    01000
    10100
    01000
    
    00000
    01010
    10100
    01000
    
    00000
    01000
    10100
    01000

    输出#2

    3
    5
    1 2 4
    2 2
    2 4
    1 3 2
    2 1
  • 输入#3

    5 3 0
    
    110
    010
    001
    011
    001

    输出#3

    1
    0
首页