310894: CF1906C. Cursed Game

Memory Limit:1024 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Cursed Gametime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard output

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 \leq N \leq 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 \leq i, j \leq 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 \leq N \leq 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().

Note

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$.

Output

题目大意:你发现了一个古老的游戏盒,被诅咒困在游戏中,需要与恶魔进行333轮游戏才能逃脱。恶魔给你999枚硬币,用于所有轮次的查询。每轮游戏开始前,恶魔会准备一张有3行3列的“秘密纸”,并在某些单元格上秘密地打洞。游戏开始时,恶魔会给你一个奇数N(3≤N≤33)。在每轮游戏中,你可以进行多次查询,每次查询花费一枚硬币。每次查询时,你需要给出一张有N行N列的“你的纸”,每个单元格被你涂成黑色或白色。对于每次查询,恶魔会计算出一个有N-2行N-2列的二进制“结果网格”。结果网格中单元格(r, c)的值按以下规则填充:

1. 恶魔将秘密纸放在你的纸上,使得你的纸的单元格(r+i-1, c+j-1)与秘密纸的单元格(i, j)对齐,对于1≤i, j≤3。
2. 只有当秘密纸的对应单元格有洞时,恶魔才能看到你的纸上的单元格颜色。
3. 如果恶魔能通过洞看到奇数个黑色单元格,则结果网格中单元格(r, c)的值为1,否则为0。

如果你赢得了所有轮次,则可以逃脱游戏。否则,如果你用完所有硬币仍未赢得所有轮次,则会永远被困住。逃脱这个被诅咒的游戏!

输入输出数据格式:
- 每轮游戏开始时,通过标准输入读取一个奇数N(3≤N≤33)。
- 对于每次查询,你可以向标准输出输出N行,每行包含N个字符。第r行的第c个字符代表你的纸上单元格(r, c)的颜色。如果单元格(r, c)被涂成黑色,则字符为'1',如果为白色,则为'0'。
- 恶魔会通过标准输入回复一行字符串。如果字符串为"CORRECT",则你赢得了当前轮次,并且如果存在下一轮,则立即开始。如果字符串为"INCORRECT",则恶魔会通过标准输入再给你N-2行,每行包含N-2个字符,代表二进制结果网格。
- 恶魔在每轮游戏开始前准备秘密纸。也就是说,评分器不是自适应的。秘密纸中至少有一个洞。
- 在所有333轮游戏中,查询的总次数不应超过999次。如果你超过最大查询次数,你的程序应该以0退出,以获得“错误答案”的判决。如果你不退出,判断结果将未定义,因为你的程序正在从已关闭的流中读取。题目大意:你发现了一个古老的游戏盒,被诅咒困在游戏中,需要与恶魔进行333轮游戏才能逃脱。恶魔给你999枚硬币,用于所有轮次的查询。每轮游戏开始前,恶魔会准备一张有3行3列的“秘密纸”,并在某些单元格上秘密地打洞。游戏开始时,恶魔会给你一个奇数N(3≤N≤33)。在每轮游戏中,你可以进行多次查询,每次查询花费一枚硬币。每次查询时,你需要给出一张有N行N列的“你的纸”,每个单元格被你涂成黑色或白色。对于每次查询,恶魔会计算出一个有N-2行N-2列的二进制“结果网格”。结果网格中单元格(r, c)的值按以下规则填充: 1. 恶魔将秘密纸放在你的纸上,使得你的纸的单元格(r+i-1, c+j-1)与秘密纸的单元格(i, j)对齐,对于1≤i, j≤3。 2. 只有当秘密纸的对应单元格有洞时,恶魔才能看到你的纸上的单元格颜色。 3. 如果恶魔能通过洞看到奇数个黑色单元格,则结果网格中单元格(r, c)的值为1,否则为0。 如果你赢得了所有轮次,则可以逃脱游戏。否则,如果你用完所有硬币仍未赢得所有轮次,则会永远被困住。逃脱这个被诅咒的游戏! 输入输出数据格式: - 每轮游戏开始时,通过标准输入读取一个奇数N(3≤N≤33)。 - 对于每次查询,你可以向标准输出输出N行,每行包含N个字符。第r行的第c个字符代表你的纸上单元格(r, c)的颜色。如果单元格(r, c)被涂成黑色,则字符为'1',如果为白色,则为'0'。 - 恶魔会通过标准输入回复一行字符串。如果字符串为"CORRECT",则你赢得了当前轮次,并且如果存在下一轮,则立即开始。如果字符串为"INCORRECT",则恶魔会通过标准输入再给你N-2行,每行包含N-2个字符,代表二进制结果网格。 - 恶魔在每轮游戏开始前准备秘密纸。也就是说,评分器不是自适应的。秘密纸中至少有一个洞。 - 在所有333轮游戏中,查询的总次数不应超过999次。如果你超过最大查询次数,你的程序应该以0退出,以获得“错误答案”的判决。如果你不退出,判断结果将未定义,因为你的程序正在从已关闭的流中读取。

加入题单

上一题 下一题 算法标签: