luogu#P7805. [JOI Open 2021] 怪兽游戏 / Monster Game
[JOI Open 2021] 怪兽游戏 / Monster Game
Background
This is an interactive problem.
The interactive library and the special judge (spj) are provided by
Please do not include the header file monster.h in your code. Add extern "C" before the Solve function, and add extern "C" bool Query(int,int); at the beginning.
Problem Description
You have raised bookworms. They are numbered from to . The strength of the -th bookworm is , where , and no two bookworms have the same strength.
You may perform at most “fight events”:
- Choose two different bookworms :
- If , the bookworm with the smaller strength wins.
- If , the bookworm with the larger strength wins.
You should minimize the number of “fight events”. You can obtain the result of each “fight event”. Find the strengths of all bookworms.
Interaction Protocol
Your program must implement the following function:
std::vector<int> Solve(int N)- For each test case, this function will be called exactly once.
- : the number of bookworms.
- This function should return the array of strengths of these bookworms.
- It must satisfy , otherwise your program will be judged as
Wrong Answer [1]. - It must satisfy , otherwise your program will be judged as
Wrong Answer [2]. - It must satisfy , otherwise your program will be judged as
Wrong Answer [3].
Your program may call the following function:
bool Query(int a, int b)- You can use this function to perform a “fight event”.
- : bookworm fights bookworm .
- If wins, return
true; otherwise returnfalse. - It must satisfy , otherwise your program will be judged as
Wrong Answer [4]. - It must satisfy , otherwise your program will be judged as
Wrong Answer [5]. - The number of calls to
Querymust not exceed . Otherwise your program will be judged asWrong Answer [6].
Special Notes
- Your program may call other functions in the standard library, or use global variables.
- Your program must not use standard input or standard output.
Input Format
See “Interaction Protocol”.
Output Format
See “Interaction Protocol”.
5
3 1 4 2 0
Hint
Explanation for Sample 1
The interactive process in the sample:
| Call | Return | Call | Return |
|---|---|---|---|
Solve(5) |
|||
Query(1, 0) |
false |
||
Query(4, 0) |
|||
Query(1, 3) |
true |
||
[3, 1, 4, 2, 0] |
|||
Sample Grader Program (Sample)
The sample grader program reads the input in the following format:
First line:
Second line:
The sample grader program reads the output in the following format:
After your program terminates successfully, the sample interactor will output the following on standard output:
- If your program is judged correct, the sample interactor will output something like
Accepted: 100, where is the number of times your program called theQueryfunction. - If your program is judged wrong, the output content is described in “Interaction Protocol”.
If your program has multiple errors, the sample interactor will only judge one of them.
Note that the interactor is adaptive for some testdata. That is, at the beginning the interactor does not have a fixed answer, and it will gradually respond according to previous calls to the Query function. It is guaranteed that there exists at least one set of answers consistent with the responses made by the interactive library.
(The original problem had a tool to test this, but the checking file cannot be found now, so it is omitted.)
Constraints and Notes
This problem uses bundled tests.
- Subtask 1 (10 pts): .
- Subtask 2 (15 pts): the actually used interactive library is not adaptive.
- Subtask 3 (75 pts): no special restrictions.
For of the data:
- .
- .
- are guaranteed to be pairwise distinct.
For Subtask 3, there is an additional scoring rule:
If your program passes all testdata, then:
- Let be the maximum number of calls to the
Queryfunction among all test cases in Subtask 3. - Your score will be computed as follows:
- If , you will get $\left\lfloor75 \times \dfrac{2.5 \times 10^4-X}{1.5 \times 10^4}\right\rfloor$ points.
- If , you will get points.
Note
Translated from JOI 2020 / 2021 Open Contest C Monster Game.
Translated by ChatGPT 5