Canadian Computing Olympiad: 2018 Day 2, Problem 1
Troy wants to play the following game with you.
He has a grid with rows and columns. Rows are numbered from to and columns are numbered from to . Let the cell at row and column be denoted as .
There are tokens numbered from to . Token is placed at where and . There may be multiple tokens at the same cell. In one second, Troy can move one token to a horizontally or vertically adjacent cell. The score of a cell is defined as the minimum number of seconds needed for Troy to move every token to this cell.
Your goal is to find the minimum score of any cell in the grid. Unfortunately, Troy does not tell you how many tokens there are or where they are placed. However, you may ask him questions. You can ask Troy to tell you the score of any cell . You may ask at most questions before Troy gets bored.
Interaction Protocol
This problem is interactive: input will be given based on questions generated by your program.
First, read one line with three integers , , .
After your program has read this line, your program may ask questions.
To ask a question about , print one line in the format ? p q
. Then, read one line with one integer , the score of .
Once your program determines the minimum score is , print one line in the format ! Z
. Your program must terminate immediately after printing this line.
The output must be flushed after every line is printed, including the last line. To flush you can use: fflush(stdout)
or cout << endl
in C/C++; System.out.flush()
in Java; flush(output)
in Pascal.
If any printed line is wrongly formatted or you ask more than questions you will get an incorrect verdict.
For every test case, the grading system will have fixed integer values , , , , , . These values will remain constant while your program is running. That is, the grading system is not adaptive.
For 5 of the 25 available marks, , and .
For an additional 5 of the 25 available marks, , and .
For an additional 5 of the 25 available marks, .
For an additional 5 of the 25 available marks, .
For the remaining 5 marks, .
Sample Interaction 1
Request to grader  Feedback from Grader 

 1 10 90 
? 1 3  9 
? 1 7  11 
? 1 4  8 
! 8 

Explanation of Output for Sample Input 1
This sample corresponds to tokens at cells , and . It is guaranteed this sample will match the sample test in the grader.
The score of cell is .
The score of cell is .
The score of cell is and this is the minimum in the grid.
For information, here are the scores in this example:
Column  1  2  3  4  5  6  7  8  9  10 

Score  13  10  9  8  9  10  11  12  13  14 
Sample Interaction 2
Request to grader  Feedback from Grader 

 5 4 170 
? 2 4  11 
? 1 4  15 
? 3 3  7 
! 7 

Explanation of Output for Sample Input 2
This sample corresponds to tokens at cells , , and .
Comments
I just found out that this contest has interactive problems.