Andrew the mushroom expert is investigating mushrooms native to Singapore.
As part of his research, Andrew collected
Andrew knows that mushroom
Fortunately, Andrew has a machine in his lab that can help with this. To use this machine, one should place two or more mushrooms in a row inside the machine (in any order) and turn the machine on. Then, the machine calculates the number of adjacent pairs of mushrooms that are of different species. For example, if you place mushrooms of species
However, as operating the machine is very expensive, the machine can be used for a limited number of times. In addition, the total number of mushrooms placed in the machine across all its uses cannot exceed
Implementation Details
You should implement the following procedure:
int count_mushrooms(int n)
: number of mushrooms collected by Andrew.- This procedure is called exactly once, and should return the number of mushrooms in species
.
The above procedure can make calls to the following procedure:
int use_machine(std::vector<int> x)
: an array of length between and inclusive, describing the labels of the mushrooms placed in the machine, in order.- The elements of
must be distinct integers from to inclusive. - Let
be the length of array . Then, the procedure returns the number of different indices , such that and mushrooms and are of different species. - This procedure can be called at most
times. - The total length of
passed to the procedureuse_machine
among all its invocations cannot exceed .
Examples
Example 1
Consider a scenario in which there are count_mushrooms
is called in the following way:
count_mushrooms(3)
This procedure may call use_machine([0, 1, 2])
, which (in this scenario) returns use_machine([2, 1])
, which returns
At this point, there is sufficient information to conclude that there is only count_mushrooms
should return
Example 2
Consider the case in which there are count_mushrooms
is called as below:
count_mushrooms(4)
The procedure may call use_machine([0, 2, 1, 3])
, which returns use_machine([1, 2])
, which returns
At this point, there is sufficient information to conclude that there are count_mushrooms
should return
Constraints
Scoring
If in any of the test cases, the calls to the procedure use_machine
do not conform to the rules mentioned above, or the return value of count_mushrooms
is incorrect, the score of your solution will be use_machine
among all test cases. Then, the score will be calculated according to the following table:
Condition | Score |
---|---|
On DMOJ, you will receive an additional
In some test cases the behavior of the grader is adaptive. This means that 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 the prior calls to use_machine
. Though, it is guaranteed that the grader answers in such a way that after each interaction there is at least one sequence of mushroom species consistent with all the answers given so far.
Sample Grader
The sample grader reads an array
- line
: - line
:
The output of the sample grader is in the following format:
- line
: the return value ofcount_mushrooms
. - line
: the number of calls touse_machine
.
Note that the sample grader is not adaptive.
Attachment Package
The sample grader along with sample test cases are available here.
Comments