시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 512 MB | 57 | 25 | 25 | 43.860% |
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:
Unfortunately, IOI-chan could not find old books in the library. But she found a machine which managed operations of the bookshelf of the library. If we specify one or more than one books by their numbers and send a query to the machine, it answers the minimum number of operations required to take only these books from the bookshelf.
IOI-chan wants to know the order of the books in the bookshelf by sending queries to the machine. However, because the answers from the machine would be the same if the order of the N books are reversed, she does not need to specify whether the books were placed from left to right or from right to left.
Because the machine is old, she can send at most 20 000 queries to the machine.
Write a program which specifies the order of the books in the bookshelf by sending at most 20 000 queries to the machine. It is not necessary to specify whether the books were placed from left to right or from right to left.
You need to submit one file.
The name of the file is library.cpp
. It should implement the following function. The program should include library.h
.
void Solve(int N)
N
is the number of books N in the bookshelf.Your program can call the following function.
int Query(const std::vector<int>& M)
M
, which is a vector of size N. For each i (1 ≤ i ≤ N), if M[i-1]
= 0, then the book i is not taken from the bookshelf. If M[i-1]
= 1, then the book i is taken from the bookshelf. If the size of M
is different from N, your program is considered as Wrong Answer [1]. For each i, M[i-1]
should be equal to either 0 or 1. There should exist at least one i (1 ≤ i ≤ N) with M[i-1]
= 1. If at least one of these two conditions is not satisfied, your program is considered as Wrong Answer [2]. If the function Query
is called more than 20 000 times, your program is considered as Wrong Answer [3].void Answer(const std::vector<int>& res)
res
is a vector of size N. It describes the order of the books in the bookshelf. For each i (1 ≤ i ≤ N), the i-th book from left in the bookshelf has number res[i-1]
. If the size of res
is different from N, your program is considered as Wrong Answer [4]. res[i-1]
should be an integer between 1 and N, inclusive. If this condition is not satisfied, your program is considered as Wrong Answer [5]. Also, the integers res[0]
, res[1]
,. . ., res[N-1]
should be different from each other. If this condition is not satisfied, your program is considered as Wrong Answer [6]
.When the function Solve terminates, if the number of calls to the function Answer
is different from 1, your program is considered as Wrong Answer [7].
If the order of the books specified by the function Solve
is different from the order of the books in the bookshelf, your program is considered as Wrong Answer [8]. It is not necessary to specify whether the books were placed from left to right or from right to left.
Here is a sample input for sample grader and corresponding function calls.
Sample Input 1 | Sample Calls | |||
---|---|---|---|---|
Call | Return | Call | Return | |
5 4 2 5 3 1 |
Solve(5) |
|||
Query( { 1,1,1,0,0 } ) |
||||
2 |
||||
Answer( { 4,2,5,3,1 } ) |
||||
(none) | ||||
In this task, it is not necessary to specify whether the books were placed from left to right or from right to left. Hence your program is considered as correct if it calls Answer( { 1,3,5,2,4 } )
whose parameters are reversed.
번호 | 배점 | 제한 |
---|---|---|
1 | 19 | N ≤ 200. |
2 | 81 | There are no additional constraints. |
C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)