Baltic Olympiad in Informatics: 2018 Day 1, Problem 3
You are looking for a place in the soil to put your pet worm, Maximus. You limit your search to a box-shaped region with dimensions centimeters which you have divided into a three-dimensional grid of cube-centimeter cells, labeled after their position in the grid . Each cell has a certain humidity which is an integer in the range . You can measure the humidity of any cell with a special sensor.
Maximus loves humid places, so you need to put him in a cell which is at least as humid as its neighboring cells, otherwise he goes away and you will have trouble finding him. In other words, you need to place Maximus in a local maximum. More precisely, you need to find a cell , such that
where a value is treated as when it is outside the box (because Maximus absolutely wants to stay in the box).
However, the number of cells can be very large, so you do not want to measure the humidity of all the cells. Therefore, in this task, you are allowed to interact with the grader, and ask for the humidity at given points. When you have found a suitable location for Maximus, give that location to the grader.
Interaction
The first line of the input contains four positive integers: , , and , where , and are the box dimensions and is the maximum number of measurements you may perform.
After that, you can write at most lines of the form ? x y z
to standard output. This asks for the value of the humidity at point . For each such line, the grader will in response write a single line with the integer , which can be read from standard input by your program.
After all these lines, your program must write out exactly one line of the form ! x y z
and terminate. This claims that the point is a suitable location for Maximus according to the criterion above. The grader will provide no response to this output.
All values of must obey . If they do not, or some line has an invalid format, or you ask for more than values, the grader will respond with -1
and exit. If this happens your program should also exit. If it continues, it may incorrectly get a verdict of Runtime Error or Time Limit Exceeded.
You must make sure to flush standard output before reading the grader's response, or else your program will get judged as Time Limit Exceeded. This works as follows in the supported languages:
Java:
System.out.println()
flushes automatically.Python:
print()
flushes automatically.C++:
cout << endl
; flushes, in addition to writing a newline. If using printf,fflush(stdout)
.Pascal:
Flush(Output)
.
The grader will be non-adaptive; that is, each test case will have a fixed set of humidity values that do not depend on what measurements are performed by the program.
Constraints
Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group. Your final score will be the maximum score of a single submission.
Group | Points | Limits |
---|---|---|
, , | ||
, , | ||
, , | ||
, , | ||
, | ||
, |
Sample Interaction
In this sample, the box has dimensions and the humidity in the three cells is . Below is an example dialogue, with the lines preceded by JUDGE
being the output of Kattis (i.e. the input to your program), and the lines preceded by YOU
being your program's output.
As is indeed greater than or equal to the neighboring values ( and ), the location is a suitable location for Maximus, and you used three queries, which was the maximum allowed number . Thus, this dialogue gives Accepted on the sample.
JUDGE: 3 1 1 3
YOU: ? 3 1 1
JUDGE: 13
YOU: ? 2 1 1
JUDGE: 14
YOU: ? 1 1 1
JUDGE: 10
YOU: ! 2 1 1
Comments