CF1772F.Copy of a Copy of a Copy
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
It all started with a black-and-white picture, that can be represented as an n×m matrix such that all its elements are either 0 or 1. The rows are numbered from 1 to n, the columns are numbered from 1 to m.
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 1 or n, nor column 1 or m) 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 k copies that were made. Additionally, you are given the initial picture. However, all k+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.
一切始于一张黑白图片,该图片可表示为一个 n×m 矩阵,其中所有元素均为 0 或 1。行编号从 1 到 n,列编号从 1 到 m。
对这张图片执行了若干次操作(可能为零次),每次操作属于以下两种类型之一:
- 选择一个不在边界上的格子(即其所在行既不是第 1 行也不是第 n 行,所在列既不是第 1 列也不是第 m 列),且该格子被四个颜色相反的相邻格子所包围(若该格子为 1,则其上下左右四个相邻格子均为 0;若为 0,则四个相邻格子均为 1),然后将该格子自身涂成相反的颜色;
- 制作当前图片的一份副本。
注意:操作顺序可以是任意的,并不一定是交替进行的。
你得到了最终结果:所有 k 次制作的副本。此外,你还得到了初始图片。然而,这 k+1 张图片(包括初始图片和 k 个副本)的顺序已被打乱。
请还原出操作序列。若存在多种可能的答案,输出任意一种即可。所有测试用例均基于真实操作序列构造,即至少存在一个合法答案。
输入格式
The first line contains three integers n,m and k (3≤n,m≤30; 0≤k≤100) — the number of rows and columns of the pictures and the number of copies made, respectively.
Then k+1 pictures follow — k copies and the initial picture. Their order is arbitrary.
Each picture consists of n lines, each consisting of m characters, each character is either 0 or 1. There is an empty line before each picture.
第一行包含三个整数 n、m 和 k(3≤n,m≤30;0≤k≤100),分别表示图片的行数、列数以及制作的副本数量。
随后是 k+1 张图片——其中 k 张为副本,另 1 张为原始图片。它们的顺序是任意的。
每张图片由 n 行组成,每行包含 m 个字符,每个字符为 0 或 1。每张图片前均有一空行。
输出格式
In the first line, print a single integer — the index of the initial picture. The pictures are numbered from 1 to k+1 in the order they appear in the input.
In the second line, print a single integer q — the number of operations.
Each of the next q lines should contain an operation. The operations should be listed in order they were applied. Each operation is one of two types:
- 1 x y — recolor a cell (x,y) (the y-th cell in the x-th row, it should not be on the border and it should be surrounded by four cells of opposite color to itself);
- 2 i — make a copy of the current picture and assign it index i (picture with index the i should be equal to the current picture).
Each index from 1 to k+1 should appear in the output exactly once — one of them is the index of the initial picture, the remaining k 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 至 k+1。
第二行输出一个整数 q —— 操作的数目。
接下来的 q 行每行应包含一个操作,按实际应用顺序列出。每个操作为以下两种类型之一:
- 1 x y —— 将单元格 (x,y)(即第 x 行第 y 列的单元格)重新着色(该单元格不能位于边界上,且其上下左右四个相邻单元格的颜色必须均与它自身相反);
- 2 i —— 复制当前图片,并将其编号设为 i(即编号为 i 的图片应与当前图片完全相同)。
编号 1 至 k+1 在输出中必须恰好各出现一次:其中一个为初始图片的编号,其余 k 个则作为第二种类型操作的参数 i 出现。
若存在多个合法答案,输出任意一个即可。测试用例均由真实操作序列构造而成,即至少存在一个合法答案。
输入输出样例
输入#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
输入解题思路,AI测评打分。不知道怎么写?