loj#P3562. 「BalticOI 2021 Day2」The Collection Game
「BalticOI 2021 Day2」The Collection Game
Description
Phew! You only narrowly escaped from prison after your disastrous debut as an art thief. A legal route into the art business seems to be a better idea after all. So, you decided to work as an art critic at the same museum where you were caught before.
This means that you visit the museum several times and produce an art review for each visit. An art review covers several pairs of rooms of the museum. For each pair, you compare the art of the two rooms during your visit and determine which room displays the art collection with the higher aesthetic value. In the end, however, you also want to survey the art in the entire museum. That is, using all your reviews, you want to rank all rooms of the museum by decreasing aesthetic value of the art collections displayed.
Because planning is the key, you decide in advance for each visit which pairs of rooms you will compare. Also, for the sake of diversity, no room should appear more than once in a single art review.
Unfortunately, your newly gained reputation in the art community proves to be an obstacle. Whenever you announce that you will compare a particular pair of rooms during your next visit, the museum might spontaneously swap the art collections of these two rooms. Your final survey and room ranking is supposed to be based on what is displayed in each room during your last visit.
Write a program that schedules no more than visits to the museum and, based on the resulting art reviews, computes a list of all rooms of the museum ordered by decreasing aesthetic value of the art collections displayed in each room at the time of your last visit.
Communication
This is a communication task. You must implement the function void solve(int N, int V )
where is the number of rooms of the museum, numbered to , and is the maximal number of visits you are allowed to make. For each testcase, this function is called exactly once. In the function, you can use the following other functions provided by the grader:
void schedule(int i, int j)
schedules a comparison of rooms and during your next visit .Immediately after a call to this function, the museum can decide to swap the art collections of rooms and .vector<int> visit()
visits the museum and performs all scheduled comparisons. This function returns an array with exactly one entry for each scheduled comparison since your last visit to the museum (that is, for each call to schedule since the last call to visit or the beginning of the program). The entry at index is if the art in room has a higher aesthetic value than in room , and otherwise. Here, and are the rooms from the -th scheduled comparison.void answer(vector⟨int⟩ 𝑟)
publishes your list of all the rooms of the museum ordered by decreasing aesthetic value. must be an array of length ; its -th entry is the room with the -th most aesthetic art collection during your last visit to the museum. You must callanswer
exactly once; your program will be automatically terminated afterwards.
If any of your function calls does not match the above format, if a room is passed more than once as a
parameter to schedule
between two calls to visit
, or if you call visit more than times, your program
will be immediately terminated and judged as Not correct for the respective testcase. You must not
write anything to standard output, otherwise you may receive the verdict Security violation!.
If you use C++, you must include the file swaps.h
in your source code. To test your program locally,
you can link your program with sample_grader.cpp
which can be found in the attachment for this
task in CMS (see below for a description of the sample grader). The attachment also contains a sample
implementation with additional explanations as swaps_sample.cpp
.
If you use Python, you can find a sample implementation as swaps_sample.py
in the attachment
which also describes the interface for Python submissions.
Sample Interaction
Consider a testcase with and where initially the rooms are ordered , , , by decreasing aesthetic value. At the beginning, the grader calls your function solve as solve(4, 50)
. Then, one possible interaction between your program and the grader could look as follows:
Your program | Return value | Explanation |
---|---|---|
schedule(1, 2) |
schedules to compare the art in rooms and . | |
schedule(3, 4) |
schedules to compare the art in rooms and , the museum swaps the art of rooms and . | |
visit() |
visits the museum and performs all comparisons; the art in room and has a higher aesthetic, value than in room and respectively. | |
schedule(2, 4) |
schedules to compare the art in rooms and . | |
visit() |
visits the museum; the art in room has a higher aesthetic value than in room . | |
answer({1, 2, 4, 3}) |
you are convinced that the rooms are ordered , , , by decreasing aesthetic value. | |
the solution is correct and is accepted. |
Note that the above queries are of course not sufficient to determine the order of the rooms with certainty: for example, the order , , , is also consistent with all answers to visit
. This order is obtained when starting from , , , and swapping the art of rooms and after the last call to schedule
.
Grader
The sample grader expects on standard input the numbers and as well as a list of integers, the rooms ordered by decreasing aesthetic value at the beginning of solve
. Then, the grader writes to standard output a protocol of all grader functions called by your program. Whenever schedule(𝑖, 𝑗)
is called, the grader expects on standard input the number if the art collections of rooms and should be swapped at that point in time, or otherwise. At the end, the grader writes one of the following messages to standard output:
Invalid input.
The input to the grader via standard input was not of the above format.Invalid schedule.
The functionschedule
was called with invalid parameters.Out of visits.
The functionvisit
was called more than times.Invalid answer.
The functionanswer
was called with invalid parameters.Wrong answer.
The functionanswer
was called with a wrong list of rooms.No answer.
The functionsolve
terminated without callinganswer
.Correct: v visit(s) used.
None of the above cases occurred and the functionvisit
was called times.
In contrast, the grader which is used for the evaluation of your submission will only output Not correct (for any of the above errors) or Correct. Both the sample grader and the grader used for evaluation will terminate your program automatically whenever one of the above errors occurs or if your program calls answer
.
Constraints
We always have and 。
- Subtask 1(5 points): and the museum never swaps art collections.
- Subtask 2(10 points): and the museum never swaps art collections.
- Subtask 3(5 points):, .
- Subtask 4(15 points):.
- Subtask 5(15 points):.
- Subtask 6(35 points):.
- Subtask 7(15 points):.
Moreover, the following holds: In each of the subtasks to you get of the points awarded for
the respective subtask if you solve all testcases in which the museum always puts the art collection
with the higher aesthetic value into room for each call to schedule
. Inside CMS this is shown as
“Group 1” of the corresponding subtask.