| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 256 MB | 161 | 23 | 20 | 12.739% |
Professor JOI’s laboratory is researching N kinds of minerals. There are 2 slices of each kind of mineral. There are 2N slices in total, numbered from 1 to 2N.
One day, as assistant Bitaro has dropped the box containing the 2N slices, he has no idea which slice and which slice are of the same kind of mineral.
The laboratory owns a device which can count the number of kinds of minerals when some slices are inserted in it, by measuring the wavelength each mineral absorbs. Bitaro is going to determine the N pairs of the same kind of mineral from the 2N slices. At first, there are no slices inserted in the device. Bitaro can perform the following operations:
So that Professor JOI will not find Bitaro bringing about troubles, Bitaro can perform these operations at most 1 000 000 times in total.
Write a program which, given the number of kinds of minerals, using the device, determines all the pairs of the same kind of mineral.
You need to submit one file.
The name of the file is minerals.cpp. It should implement the following function. The program should include minerals.h.
void Solve(int N)N represents N, the number of kinds of minerals.Your program can call the following functions.
int Query(int x)x. This must satisfy 1 ≤ x ≤ 2N. Otherwise, your program is considered as Wrong Answer [1].void Answer(int a, int b)a and b represent that the a-th slice and the b-th slice are the same kind of mineral. These must satisfy 1 ≤ a ≤ 2N and 1 ≤ b ≤ 2N. Otherwise, your program is considered as Wrong Answer [3]. If the same value appears more than once in a or b in total, your program is considered as Wrong Answer [4]. If slices of different kinds of mineral are specified, your program is considered as Wrong Answer [5].The function Answer must be called exactly N times. If the number of calls to the function Answer is not N at the end of the execution of the function Solve, your program is considered as Wrong Answer [6].
Xi and Yi (1 ≤ i ≤ N) denote that the Xi-th slice and the Yi-th slice are the same kind of mineral.
Here is a sample input for the sample grader and corresponding function calls.
| Sample Input 1 | Sample Calls | ||
|---|---|---|---|
| Call | Call | Return | |
4 1 5 2 6 3 4 7 8 |
Solve(4) |
||
Query(1) |
1 |
||
Query(2) |
2 |
||
Query(5) |
2 |
||
Query(2) |
1 |
||
Answer(3, 4) |
(none) |
||
Answer(5, 1) |
(none) |
||
Answer(8, 7) |
(none) |
||
Answer(2, 6) |
(none) |
||
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 6 | N ≤ 100. |
| 2 | 25 | N ≤ 15 000, 1 ≤ Xi ≤ N, N + 1 ≤ Yi ≤ 2N (1 ≤ i ≤ N). |
| 3 | 9 | N ≤ 15 000. |
| 4 | 30 | N ≤ 38 000. |
| 5 | 5 | N ≤ 39 000. |
| 6 | 5 | N ≤ 40 000. |
| 7 | 5 | N ≤ 41 000. |
| 8 | 5 | N ≤ 42 000. |
| 9 | 10 | No additional constraints. |
C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)