#abc269e. E - Last Rook
E - Last Rook
Score : points
问题描述
这是一项互动任务(您的程序通过输入和输出与裁判程序进行交互)。
我们有一个 × 的棋盘和 个车。以下面的方式表示棋盘上从上到下第 行、从左到右第 列的格子:。
考虑在棋盘的格子上放置车。您必须放置车,确保满足以下所有条件:
- 没有行包含两个或更多的车。
- 没有列包含两个或更多的车。
现在,已经有 个车按照上述条件被放置在棋盘上。您需要选择一个没有被车占据的格子,并在该格子上放置一个车。(可以证明,在这些条件下至少存在一个可放置车的格子。)
但是,您不能直接看到棋盘上哪些格子被车占据了。
- 您可以选择整数 、、 和 ,使得 且 ,然后询问在由格子 形成的矩形区域内车的数量,其中满足 且 。
使用这种方式最多提问不超过 次,找到并确定一个放置车的格子。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
This is an interactive task (where your program interacts with the judge's program via input and output).
We have an -by- chessboard and rooks. Below, the square at the -th row from the top and -th column from the left is denoted by .
Consider placing the rooks on squares of the chessboard. Here, you have to place the rooks so that all of the following conditions are satisfied.
- No row contains two or more rooks.
- No column contains two or more rooks.
Now, rooks are placed on the chessboard so that all of the above conditions are satisfied. You will choose a square that is not occupied by a rook and place a rook on that square. (It can be proved that there is at least one square on which a rook can be placed under the conditions.)
However, you cannot directly see which squares of the chessboard are occupied by a rook.
Instead, you may ask at most questions to the judge in the following manner.
- You choose integers , , , and such that , and ask the number of rooks in the rectangular region formed by the squares such that .
Find a square to place a rook.
Constraints
- is an integer.
Input and Output
This is an interactive task (where your program interacts with the judge's program via input and output).
First, receive the size of the chessboard, , from Standard Input.
Next, repeat asking a question until you find a square to place a rook.
A question should be printed to Standard Output in the following format:
The response will be given from Standard Input in the following format:
Here, is the response to the question, or -1
if the question is invalid or more than questions have been asked.
When the judge returns -1
, the submission is already regarded as incorrect. In this case, terminate the program immediately.
When you find a square to place a rook, let be that square and print an answer in the following format. Then, terminate the program immediately.
If there are multiple appropriate answers, any of them will be accepted.
Notes
- Each time you print something, end it with a newline and then flush Standard Output. Otherwise, you may get a TLE verdict.
- If an invalid output is printed during the interaction, the verdict will be indeterminate.
- Terminate the program immediately after printing an answer. Otherwise, the verdict will be indeterminate.
Sample Interaction
Below is an interaction where and the rooks are placed on and .
Input | Output | Description |
---|---|---|
3 | Judge first gives the integer $N$. | |
? 1 2 1 3 | Participant asks a question with $(A,B,C,D)=(1,2,1,3)$. | |
2 | Judge returns the answer to the question, which is $2$. | |
? 2 3 1 1 | Participant asks a question with $(A,B,C,D)=(2,3,1,1)$. | |
1 | Judge returns the answer to the question, which is $1$. | |
? 1 3 3 3 | Participant asks a question with $(A,B,C,D)=(1,3,3,3)$. | |
0 | Judge returns the answer to the question, which is $0$. | |
! 3 3 | Participant finds the answer to be $(3, 3)$ and prints it. |
update @ 2024/3/10 11:21:43