#P6837. [IOI 2020] 数蘑菇
[IOI 2020] 数蘑菇
Description
Mushroom expert Andrew is studying local mushrooms in Singapore.
As part of the study, Andrew collected mushrooms, numbered from to . Each mushroom belongs to one of two species, called or .
Andrew knows that mushroom belongs to species , but since the two species look very similar, he does not know whether mushrooms to are or .
Fortunately, Andrew has a machine in his lab that can help. To use the machine, you put two or more mushrooms into the machine and arrange them in a line (in any order), then turn on the machine. The machine will compute the number of adjacent pairs of mushrooms that are not of the same species. For example, if you put mushrooms of species (in this order) into the machine, the result should be .
However, because operating the machine is very expensive, it can only be used a limited number of times. Moreover, across all uses of the machine, the total number of mushrooms placed into the machine cannot exceed . Use this machine to help Andrew count how many mushrooms of species he collected.
Implementation details
You need to implement the following function:
int count_mushrooms(int n)
n: the number of mushrooms Andrew collected.- This function will be called exactly once, and it should return the number of mushrooms of species .
The above function may call the following function:
int use_machine(vector<int> x)
x: an array of length between and (inclusive), giving in order the indices of the mushrooms placed into the machine.- The elements of
xmust be distinct integers between and (inclusive). - Suppose the length of
xis . Then this function returns the number of indices such that and and belong to different species. - This function can be called at most times.
- Across all calls to
use_machine, the sum of the lengths of all arrays passed touse_machinemust not exceed .
Hint
Sample explanation
Example 1
Consider the following scenario: there are mushrooms, with species in order . The function count_mushrooms is called in the following way:
count_mushrooms(3)
This function can call use_machine([0, 1, 2]), which in this scenario returns . The function then calls use_machine([2, 1]), which returns .
At this point, there is enough information to conclude that there is only mushroom of species . Therefore, count_mushrooms should return .
Example 2
Consider the following example: there are mushrooms, with species in order . The function count_mushrooms is called as follows:
count_mushrooms(4)
This function can call use_machine([0, 2, 1, 3]), which returns . It then calls use_machine([1,2]), which returns .
At this point, there is enough information to conclude that there are mushrooms of species . Therefore, count_mushrooms should return .
Constraints
Scoring
For all test cases, if your calls to use_machine do not satisfy the requirements described above, or if the return value of count_mushrooms is not correct, your score will be . Otherwise, let be the maximum number of calls to use_machine among all test cases. Then your score will be computed according to the following table:
| Condition | Score |
|---|---|
On some test cases, the behavior of the grader is adaptive. That is, in these test cases, the grader does not have a fixed sequence of mushroom species. Instead, the answers given by the grader may depend on previous calls to use_machine.
However, it is guaranteed that the answers given by the grader satisfy the following: after each interaction, there exists at least one sequence of mushroom species that is consistent with all answers given so far.
Example grader
The example grader reads an integer array , which gives the species of the mushrooms. For all , means mushroom is of species , and means mushroom is of species . The example grader reads input in the following format:
Line :
Line :
The output of the example grader is in the following format:
Line : the return value of count_mushrooms.
Line : the number of calls to use_machine.
Note that the example grader is not adaptive.
Translated by ChatGPT 5
京公网安备 11011102002149号