| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 1024 MB | 34 | 15 | 15 | 46.875% |
After several hundred years had passed, JOI city became a ruined city. IOI-chan, an explorer, is now exploring the area where the library was built. According to the results of exploration, the following are known:
It often happens that the arrangement of the books changes. We know that in this library, the books were put back in the correct arrangement by repeating the following operation.
operation Let book $x$ be the leftmost book among the books that the place of it differs from the place of the correct arrangement. Also let book $y$ be the book in the current arrangement at the place where book $x$ is placed in the correct arrangement. Swap the places of book $x$ and book $y$.
Although IOI-chan found the old books of the library, she could not know the corrent arrangement. But she found an old machine which managed operations of the bookshelf of the library. If we specify the arrangement of the $N$ books and send a query to the machine, it answers the number of operations required to put back all the books in the correct arrangement. IOI-chan wants to know the correct arrangement of the books by sending queries to the machine. Because the machine is old, she can send at most 5ドル,円 000$ queries to the machine.
Write a program which, given infomation of the bookshelf, specify the correct arrangement of the books by sending at most 5ドル,円 000$ queries.
You need to submit one file.
The file is library3.cpp. It should implement the following function. The program should include library3.h using the preprocessing directive #include.
void solve(int N)
This function is called only once for each test case.
N is the number of books $N$.In library3.cpp, you can call the following function
int query(const std::vector<int> a)
Using this function, IOI-chan send a queries to the machine.
a is an array of length $N,ドル and it indicates the arrangement of $N$ books to be specified in the query. It means, in the specified arrangement, book a[i] (0ドル ≤ i ≤ N - 1$) must be placed at place $i$.a must be $N$. If this condition is not met, your program will be judged as Wrong Answer [1].a must be between 0ドル$ and $N -1$. If this condition is not met, your program will be judged as Wrong Answer [2].a must be different from all the others. If this condition is not met, your program will be judged as Wrong Answer [3].query strictly more than 5ドル,円 000$ times. If it is called more than 5ドル,円 000$ times, your program will be judged as Wrong Answer [4].void answer(std::vector<int> b)
Your program answers the corrent arrangement of the books by calling this function.
b is an array of length $N,ドル and it indicates the arrangement of $N$ books to be specified in the answer. It means, in the answered arrangement, book b[i] (0ドル ≤ i ≤ N - 1$) must be placed at place $i$.b must be $N$. If this condition is not met, your program will be judged as Wrong Answer [5].b must be between 0ドル$ and $N -1$. If this condition is not met, your program will be judged as Wrong Answer [6].b must be different from all the others. If this condition is not met, your program will be judged as Wrong Answer [7].answer must be called exactly one time. If it is called more than 1ドル$ time, your program will be judged as Wrong Answer [9]. When the function solve terminates, if the function answer has not been called, your program will be judged as Wrong Answer [10].Important Notice
You can download an archive file from the contest webpage which contains the sample grader to test your program. The archive file also contains a sample source file of your program.
The sample grader is the file grader.cpp. In order to test your program, put grader.cpp, library3.cpp, library3.h in the same directory, and run the following command to compile your programs. Instead, you may run compile.sh contained in the archive file.
g++ -std=gnu++20 -O2 -o grader grader.cpp library3.cpp
When the compilation succeeds, the executable file grader is generated.
Note that the actual grader is different from the sample grader. The sample grader will be executed as a single process, which will read input data from the standard input and write the results to the standard output.
Input for the Sample Grader
The sample grader reads the following data from the standard input.
$N$
$B_0$ $B_1$ $\cdots$ $B_{N-1}$
$B_i$ (0ドル ≤ i ≤ N - 1$) is the book number placed at the place $i$ in the correct arrangement.
Output of the Sample Grader
The sample grader outputs the following information to the standard output and the standard error output (quotes for clarity).
query as “Accepted: 3000”.Wrong Answer [3]”.If your program satisfies the conditions of several types of Wrong Answer, the sample grader reports only one of them.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 2 | $N ≤ 6$. |
| 2 | 19 | $N ≤ 100$. |
| 3 | 79 | No additional constraints. |
Here is a sample input for the sample grader and corresponding function calls.
| Sample Input 1 | Sample Function Calls | ||
|---|---|---|---|
| Call | Call | Return value | |
4 2 0 3 1 |
solve(4) |
||
query([0, 1, 2, 3]) |
3 |
||
query([1, 3, 0, 2]) |
2 |
||
query([3, 0, 1, 2]) |
2 |
||
query([2, 0, 3, 1]) |
0 |
||
answer([2, 0, 3, 1]) |
|||
For example, the call of query([0, 1, 2, 3]) specify the arrangement that books 0ドル,ドル 1ドル,ドル 2ドル,ドル 3ドル$ are placed at places 0ドル,ドル 1ドル,ドル 2ドル,ドル 3ドル$ respectively. The operation will be repeated as follows.
Because number of operation required to put back all the books in the correct arrangement is 3ドル,ドル the return value is 3ドル$.
This sample input satisfies the constraints of all subtasks.
C++17, C++20, C++17 (Clang), C++20 (Clang)