IOI '22 P5 - Rarest Insects
View as PDFThere are  insects, indexed from 
 to 
, running around Pak Blangkon's house.
Each insect has a type, which is an integer between 
 and 
 inclusive.
Multiple insects may have the same type.
Suppose insects are grouped by type. We define the cardinality of the most frequent insect type as the number of insects in a group with the most number of insects. Similarly, the cardinality of the rarest insect type is the number of insects in a group with the least number of insects.
For example, suppose that there are  insects, whose types are 
.
In this case, the cardinality of the most frequent insect type is 
. The groups with the most number of insects are type 
 and type 
, each consisting of 
 insects.
The cardinality of the rarest insect type is 
. The groups with the least number of insects are type 
, type 
, and type 
, each consisting of 
 insect.
Pak Blangkon does not know the type of any insect. He has a machine with a single button that can provide some information about the types of the insects. Initially, the machine is empty. To use the machine, three types of operations can be performed:
- Move an insect to inside the machine.
 - Move an insect to outside the machine.
 - Press the button on the machine.
 
Each type of operation can be performed at most  times.
Whenever the button is pressed, the machine reports the cardinality of the most frequent insect type, considering only insects inside the machine.
Your task is to determine the cardinality of the rarest insect type among all  insects in Pak Blangkon's house by using the machine.
Additionally, in some subtasks, your score depends on the maximum number of operations of a given type that are performed (see Subtasks section for details).
Implementation Details
You should implement the following procedure:
int min_cardinality(int N)
: the number of insects.
- This procedure should return the cardinality of the rarest insect type among all 
insects in Pak Blangkon's house.
 - This procedure is called exactly once.
 
The above procedure can make calls to the following procedures:
void move_inside(int i)
: the index of the insect to be moved inside the machine. The value of
must be between
and
inclusive.
- If this insect is already inside the machine, the call has no effect on the set of insects in the machine. However, it is still counted as a separate call.
 - This procedure can be called at most 
times.
 
void move_outside(int i)
: the index of the insect to be moved outside the machine. The value of
must be between
and
inclusive.
- If this insect is already outside the machine, the call has no effect on the set of insects in the machine. However, it is still counted as a separate call.
 - This procedure can be called at most 
times.
 
int press_button()
- This procedure returns the cardinality of the most frequent insect type, considering only insects inside the machine.
 - This procedure can be called at most 
times.
 - The grader is not adaptive. That is, the types of all 
insects are fixed before
min_cardinalityis called. 
Example
Consider a scenario in which there are  insects of types 
 respectively.
The procedure 
min_cardinality is called in the following way:
min_cardinality(6)
The procedure may call move_inside, move_outside, and press_button as follows.
| Call | Return value | Insects in the machine | Types of insects in the machine | 
|---|---|---|---|
move_inside(0) | 
|||
press_button() | 
|||
move_inside(1) | 
|||
press_button() | 
|||
move_inside(3) | 
|||
press_button() | 
|||
move_inside(2) | 
|||
move_inside(4) | 
|||
move_inside(5) | 
|||
press_button() | 
|||
move_inside(5) | 
|||
press_button() | 
|||
move_outside(5) | 
|||
press_button() | 
At this point, there is sufficient information to conclude that the cardinality of the rarest insect type is .
Therefore, the procedure 
min_cardinality should return .
In this example, move_inside is called  times, 
move_outside is called  time, and 
press_button is called  times.
Constraints
Subtasks
- (10 points) 
 - (15 points) 
 - (75 points) No additional constraints.
 
If in any of the test cases, the calls to the procedures move_inside, move_outside, or press_button do not conform to the constraints described in Implementation Details, or the return value of min_cardinality is incorrect, the score of your solution for that subtask will be .
Let  be the maximum of the following three values: the number of calls to 
move_inside, the number of calls to move_outside, and the number of calls to press_button.
In subtask 3, you can obtain a partial score.
Let  be the maximum value of 
 across all test cases in this subtask.
Your score for this subtask is calculated according to the following table:
| Condition | Points | 
|---|---|
Output isn't correct in CMS) | 
|
Sample Grader
Let  be an array of 
 integers where 
 is the type of insect 
.
The sample grader reads the input in the following format:
- line 
:
 - line 
:
 
If the sample grader detects a protocol violation, the output of the sample grader is Protocol Violation: <MSG>, where <MSG> is one of the following:
invalid parameter: in a call tomove_insideormove_outside, the value ofis not between
and
inclusive.
too many calls: the number of calls to any ofmove_inside,move_outside, orpress_buttonexceeds.
Otherwise, the output of the sample grader is in the following format:
- line 
: the return value of
min_cardinality - line 
:
 
Attachment Package
The sample grader along with sample test cases are available here.
Comments