Guess the Perimeter solution codeforces
Let us call a point of the plane admissible if its coordinates are positive integers less than or equal to .
There is an invisible rectangle such that:
- its vertices are all admissible;
- its sides are parallel to the coordinate axes;
- its area is strictly positive.
Your task is to guess the perimeter of this rectangle.In order to guess it, you may ask at mostqueries.
In each query, you choose a nonempty subset of the admissible points and you are told how many of the chosen points are inside or on the boundary of the invisible rectangle.
To ask a query (of the kind described in the statement), you shall print two lines:
- In the first line print “? ” (without the quotes) where ( ) is the number of chosen points.
- In the second line print integers ( for ) where are the distinct admissible chosen points (the order of the points is not important).
After this, you should read an integer — the number of chosen points that are inside or on the boundary of the invisible rectangle.When you have identified the perimeter ! ” (without quotes) and terminate your program.of the invisible rectangle, you must print “
If you ask more than Wrong Answer.queries or if one of the queries is malformed, the interactor terminates immediately and your program receives verdict
The interactor may be adaptive (i.e., the hidden rectangle may not be chosen before the beginning of the interaction).
After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
- fflush(stdout) or cout.flush() in C++;
- System.out.flush() in Java;
- flush(output) in Pascal;
- stdout.flush() in Python;
- see documentation for other languages.
To hack a solution, use the following format.
The input has only one line, containing theintegers , , , ( , ) — is the bottom-left vertex of the hidden rectangle and is the top-right vertex of the hidden rectangle.
Note that for hacks the interaction won’t be adaptive.
13 5 123 80
2 2 4 4
1 1 200 200
The following is an example of interaction for the first sample intended to show the format of the queries.
For the second sample, a possible interaction is the following.
The situation is shown in the following picture:
- the rectangle of vertices and , shown in red;
- the rectangle of vertices and , shown in blue.
Since both of these rectangles have perimeter, this is the final answer.