atcoder#ABC269E. [ABC269E] Last Rook
[ABC269E] Last Rook
Score : points
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.
N
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:
? A B C D
The response will be given from Standard Input in the following format:
T
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.
! X Y
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 . | |
? 1 2 1 3 |
Participant asks a question with . | |
2 |
Judge returns the answer to the question, which is . | |
? 2 3 1 1 |
Participant asks a question with . | |
1 |
Judge returns the answer to the question, which is . | |
? 1 3 3 3 |
Participant asks a question with . | |
0 |
Judge returns the answer to the question, which is . | |
! 3 3 |
Participant finds the answer to be and prints it. |