#P8126. [BalticOI 2021] The Collection Game (Day2)
[BalticOI 2021] The Collection Game (Day2)
Description
You want to visit exhibition halls in a museum. Because you have a criminal record (BalticOI 2021 Day2 A), the museum only allows you to make at most visits. In each visit, you can perform multiple comparisons. Each comparison lets you compare a pair of halls , and then you will know which of the two halls has the higher artistic value. To avoid wasting your time, in each visit, each hall can be compared at most once.
Unfortunately, because of your criminal record, the museum may swap the exhibits in the pair of halls you compare, so the artistic value relation you obtain will be reversed. In the end, your ranking for each of the halls should be based on the last comparison involving that hall.
Now, determine the permutation of artistic values of these halls through comparisons.
Interaction
You need to implement the function void solve(int N, int V), where is the number of halls and is the maximum number of visits.
The function solve is called only once, and inside solve you may call:
void schedule(int i, int j)Compare the pair of halls . The museum may swap the exhibits.vector<int> visit()Finalize the comparisons of the current visit. It returns a sequence of results in the same order as the scheduled pairs . For each pair, if hall has higher artistic value than hall , then , otherwise .void answer(vector<int> r)Here is a sequence of length , and it is a permutation of . means hall ranks -th in artistic value among the halls.
If your function calls do not satisfy the requirements (for example, in a single visit you compare the same hall more than time, or you make more than visits), your program will be stopped immediately and judged as Not correct. Do not print anything to standard output, otherwise you will be judged as Security violation!.
If you use C++, include the swaps.h header file. If you want to test your program, you can download sample_grader.cpp and swaps_sample.cpp from the attachments below, which are used for correctness checking and as a sample explanation.
If you use Python, you can download swaps_sample.py from the attachments below for testing.
The interactive library expects one line in standard input:
- One line with two integers .
Then the interactive library will call your program. Finally, the interactive library will print information to standard output:
| Message | Meaning |
|---|---|
| Invalid input. | Invalid standard input format |
| Invalid schedule. | Invalid call to schedule |
| Out of visits. | visit is called more than times |
| Invalid answer. | Invalid call to answer |
| Wrong answer. | The permutation passed to answer is incorrect |
| No answer. | solve did not call answer |
| Correct: v visit(s) used. | None of the above happened, and visit was called times |
For the error cases above, the interactive library will only output Not correct, or Correct when it is correct. Whenever any of the above errors occurs, or when your program calls answer, the program will be terminated automatically.
Input Format
See “Interaction”.
Output Format
See “Interaction”.
4 50
Hint
Sample 1 Explanation
, . The following is one valid sequence of calls:
| Your program | Return value | Does the museum swap |
|---|---|---|
schedule(1,2) |
- | No |
schedule(3,4) |
Yes | |
visit() |
{1,0} |
- |
schedule(2,4) |
- | No |
visit() |
{1} |
- |
answer({1,2,4,3}) |
- |
For the table above, also satisfies the requirements. If the third visit swaps, then satisfies the requirements.
Constraints and Notes
This problem uses bundled testdata.
- Subtask 1 (5 pts): , the museum never swaps exhibits.
- Subtask 2 (10 pts): , the museum never swaps exhibits.
- Subtask 3 (5 pts): , .
- Subtask 4 (15 pts): .
- Subtask 5 (15 pts): .
- Subtask 6 (35 pts): .
- Subtask 7 (15 pts): .
For of the testdata, , .
Notes
Translated from BalticOI 2021 Day2 B The Collection Game。
Translated by ChatGPT 5
京公网安备 11011102002149号