CF1906C.Cursed Game
NOI/NOI+/CTSC
通过率:0%
时间限制:1.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You found an antique box in your warehouse and decided to open it. The moment you open the box, it traps you into a cursed game where you are playing against a demon. The game consists of 333 rounds and you have to win all rounds in order to escape. The demon also gives you 999 coins that you can use throughout all rounds.
Note that in this problem, denote cell (r,c) of a grid as the cell in row r and column c of the grid.
Before the start of each round, the demon will prepare a secret paper, which can be represented as a grid with 3 rows and 3 columns, both numbered from 1 to 3. The demon will secretly put a hole in one or more cells, and you are not aware which cells have a hole in it. Then, the round starts with the demon giving you an odd integer N (3≤N≤33).
Within each round, you can ask the demon several queries, each costing you one coin. For each query, you are allowed to give the demon your paper, which can be represented as a grid with N rows and N columns, both numbered from 1 to N. Each cell is coloured either black or white by you.
For each of your query, the demon will calculate a binary result grid with N−2 rows and N−2 columns, both numbered from 1 to N−2. The value on cell (r,c) of the result grid is filled as follows.
- The demon will put the secret paper on top of your paper such that the cell (r+i−1,c+j−1) of your paper aligns with the cell (i,j) of the secret paper, for 1≤i,j≤3.
- The demon can only see the colour of the cell in your paper if the corresponding cell in the secret paper has a hole in it.
- The value on cell (r,c) of the result grid is 1 if there is an odd number of black cells that it can see through the holes, or 0 otherwise.
You win the round if the result grid consists of only the values 1. Otherwise, the demon will give you the result grid as a feedback, and the round continues.
If you have spent all the coins and still did not win all the rounds, then you will be trapped forever. Escape the cursed game!
Interaction
Each round is started with an odd integer N (3≤N≤33) which can be read through standard input.
Then, for each query that you give to the demon, you can output N lines to standard output. Each of the N lines consists of N characters. The c-th character of the r-th line represents the colour of cell (r,c) in your paper. The character should be 1 if (r,c) is coloured black, or 0 if coloured white.
The demon will reply with one line consisting of a string, which can be read through standard input.
- If the string is CORRECT, then you win the current round and the next round (if exists) will immediately start.
- If the string is INCORRECT, then the demon will give you N−2 more lines which can be read through standard input. Each of the N−2 lines consists of N−2 characters, representing the binary result grid as explained in the description.
The demon prepares the secret paper before the start of each round. In other words, the grader is NOT adaptive. There will be at least one hole in the secret paper.
The total number of queries across all 333 rounds should not exceed 999. If you exceed the maximum number of queries, you should terminate your program with 0 to receive the verdict Wrong Answer. If you do not terminate, the judging result would be undefined because your program is reading from a closed stream.
Do not forget to flush output buffers after each output. In C you can use fflush(stdout). In C++ you can use fflush(stdout) or cout « flush. In Java you can use method flush for output stream, for example, System.out.flush(). In Python you can use stdout.flush().
你在仓库中发现了一个古董箱子,决定将其打开。就在你打开箱子的瞬间,你被卷入了一场受诅咒的游戏,对手是一个恶魔。游戏共进行 333 轮,你必须赢得所有轮次才能逃脱。恶魔还会给你 999 枚硬币,供你在全部轮次中使用。
注意:在本题中,用 (r,c) 表示网格中第 r 行、第 c 列的格子。
每轮开始前,恶魔会准备一张秘密纸片,该纸片可表示为一个 3×3 的网格,行列编号均为 1 至 3。恶魔会在其中一个或多个格子上悄悄打孔,而你无法得知哪些格子有孔。随后,本轮开始,恶魔会向你给出一个奇数 N(满足 3≤N≤33)。
在每轮中,你可以向恶魔提出若干次查询,每次查询消耗一枚硬币。每次查询时,你需向恶魔提交一张你自己的纸片,该纸片可表示为一个 N×N 的网格,行列编号均为 1 至 N。你需将每个格子涂成黑色或白色。
对于你的每一次查询,恶魔将计算出一个二进制结果网格,其大小为 (N−2)×(N−2),行列编号均为 1 至 N−2。结果网格中格子 (r,c) 的取值规则如下:
- 恶魔将秘密纸片覆盖在你的纸片之上,使得秘密纸片中格子 (i,j)(其中 1≤i,j≤3)与你的纸片中格子 (r+i−1,c+j−1) 对齐;
- 恶魔仅当秘密纸片对应位置有孔时,才能看到你纸片上该格子的颜色;
- 结果网格中格子 (r,c) 的值为 1,当且仅当恶魔透过孔所能看到的黑色格子个数为奇数;否则为 0。
若结果网格中所有值均为 1,则你赢得本轮;否则,恶魔将把该结果网格作为反馈返回给你,本轮继续进行。
若你耗尽全部硬币却仍未赢得所有轮次,则你将永远被困于此!快逃离这场受诅咒的游戏!
交互方式
每轮开始时,你会从标准输入读入一个奇数 N(满足 3≤N≤33)。
接着,对于你提出的每一次查询,你需要向标准输出写入 N 行,每行包含 N 个字符。第 r 行的第 c 个字符表示你纸片中格子 (r,c) 的颜色:若为黑色则输出 1,若为白色则输出 0。
恶魔将通过标准输入向你返回一行字符串:
- 若字符串为
CORRECT,则你赢得当前轮次,下一轮(若存在)立即开始; - 若字符串为
INCORRECT,则恶魔会额外提供 N−2 行,你可从标准输入读入。这 N−2 行每行含 N−2 个字符,即前述描述中定义的二进制结果网格。
恶魔在每轮开始前即已固定秘密纸片。换言之,评测器非自适应(non-adaptive)。秘密纸片中至少有一个孔。
你在全部 333 轮中使用的查询总数不得超过 999。若你超出最大查询次数,应以退出码 0 终止程序,以获得“答案错误”(Wrong Answer)判据;若未主动终止,由于程序试图从已关闭的输入流中读取数据,评测结果将为未定义。
每次输出后,请务必刷新输出缓冲区。在 C 语言中可使用 fflush(stdout);在 C++ 中可使用 fflush(stdout) 或 cout << flush;在 Java 中可对输出流调用 flush() 方法,例如 System.out.flush();在 Python 中可使用 sys.stdout.flush()。
说明/提示
Sample Interaction #1
The following interaction only shows 2 rounds. The actual interaction stays until you win all 333 rounds or you run out of coins.

Explanation for the sample interaction #1
For the first round, the following illustration shows how the demon finds the value in cell (1,1) of the result grid for the first and second queries. The grey-colored square represents the secret paper, and the circles represent the holes. In the first query, there are 4 black cells that can be seen through the holes, therefore the value in cell (1,1) of the result grid is 0. In the second query, there are 5 black cells that can be seen through the holes, therefore the value in cell (1,1) of the result grid is 1. As the result grid consists of only 1, the first round ends.

For the second round, the following illustration shows how the demon find the value in cell (2,1) of the result grid for the first query. Since there are 2 black cells that can be seen through the holes, the value in cell (2,1) is 0.

示例交互 #1
以下交互仅展示 2 轮。实际交互将持续进行,直至你赢得全部 333 轮,或你的金币耗尽为止。

示例交互 #1 的说明
在第一轮中,下图展示了恶魔如何通过第一次和第二次查询,确定结果网格中单元格 (1,1) 处的值。灰色正方形代表秘密纸张,圆圈代表孔洞。在第一次查询中,有 4 个黑色单元格可通过孔洞被看到,因此结果网格中单元格 (1,1) 的值为 0;在第二次查询中,有 5 个黑色单元格可通过孔洞被看到,因此结果网格中单元格 (1,1) 的值为 1。由于结果网格仅包含 1,第一轮结束。

在第二轮中,下图展示了恶魔如何通过第一次查询,确定结果网格中单元格 (2,1) 处的值。由于有 2 个黑色单元格可通过孔洞被看到,因此单元格 (2,1) 的值为 0。

输入解题思路,AI测评打分。不知道怎么写?