시간 제한 | 메모리 제한 | 제출 | 정답 | 맞은 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 512 MB | 0 | 0 | 0 | 0.000% |
Anna drew a regular polygon with n vertices numbered from 0 to n − 1 in clockwise order. Later she triangulated it by drawing n − 3 diagonals that do not intersect each other. Except possibly where they touch at their endpoints. Diagonal is defined as straight lines between two different vertices that aren’t sharing a side.
First, let's define the distance from the vertex A to the diagonal D. Suppose we start at vertex A and keep moving to the next vertex in clockwise order until we reach one of the endpoints of D. The number of sides traversed will be called left_distance. Similarly, right_distance is the number of sides traversed if we start at A and move counter-clockwise until reaching D. The distance from A to D is the maximum of left_distance and right_distance
In the example image the distance from vertex 0 to diagonal (1,5) is 2 with left_distance being 1 and right_distance being 2. As for diagonal (0,5) the distance from vertex 0 is 5, with left_distance=5 and right_distance=2.
Anna wants to make a challenge for Jacob. Jacob does not know which diagonals are drawn at all. He only knows the value of n, but can ask Anna multiple times about some pairs of vertices and she will tell him whether a diagonal is present between those vertices. Jacob’s goal is to find the closest (with distance defined as above) drawn diagonal from the vertex 0. You are going to help him to achieve his goal by asking Anna a limited amount of questions.
You should implement the following function in your submission:
int solve(int n)
The above function can make calls to the following function:
int query(int x, int y)
Here is a sample input for grader and corresponding function calls. This input is shown in an image above.
The only line in the input has one integer: n
Sample grader will print each query call to the stdout and you have to manually answer it with 1 or 0.
Sample Input to grader | Sample Calls | |||
---|---|---|---|---|
Calls | Returns | Calls | Returns | |
7 |
solve(7) |
|||
query(0, 3) |
||||
0 | ||||
query(0, 5) |
||||
1 | ||||
query(1, 5) |
||||
1 | ||||
solve returns 1 · 7 + 5 = 12 |
||||
Correct! |
Let’s denote q as the amount of question you used on a single test. Additionally, w = n·(n-3)/2.
C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)