| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 3 초 | 2048 MB | 25 | 8 | 8 | 32.000% |
It has been an hour into a Codeforces contest, when you notice that another contestant in your room has solved a problem using an unordered_set. Time to hack!
You know that unordered_set uses a hash table with $n$ buckets, which are numbered from 0ドル$ to $n − 1$. Unfortunately, you do not know the value of $n$ and wish to recover it.
When you insert an integer $x$ into the hash table, it is inserted to the ($x \bmod n$)-th bucket. If there are $b$ elements in this bucket prior to the insertion, this will cause $b$ hash collisions to occur.
By giving $k$ distinct integers $x[0],x[1], \dots ,x[k − 1]$ to the interactor, you can find out the total number of hash collisions that had occurred while creating an unordered_set containing the numbers. However, feeding this interactor $k$ integers in one query will incur a cost of $k$.
For example, if $n = 5,ドル feeding the interactor with $x = [2, 15, 7, 27, 8, 30]$ would cause 4ドル$ collisions in total:
| Operation | New collisions | Buckets |
|---|---|---|
| initially | $-$ | $[],[],[],[],[]$ |
| insert $x[0] = 2$ | 0ドル$ | $[],[],[2],[],[]$ |
| insert $x[1] = 15$ | 0ドル$ | $[15],[],[2],[],[]$ |
| insert $x[2] = 7$ | 1ドル$ | $[15],[],[2, 7],[],[]$ |
| insert $x[3] = 27$ | 2ドル$ | $[15],[],[2, 7, 27],[],[]$ |
| insert $x[4] = 8$ | 0ドル$ | $[15],[],[2, 7, 27],[8],[]$ |
| insert $x[5] = 30$ | 1ドル$ | $[15, 30],[],[2, 7, 27],[8],[]$ |
Note that the interactor creates the hash table by inserting the elements in order into an initially empty unordered_set, and a new empty unordered_set will be created for each query. In other words, all queries are independent.
Your task is to find the number of buckets $n$ using total cost of at most 1ドル,円 000,円 000$.
You should implement the following procedure:
int hack()
Within this procedure, you may call the following procedure:
long long collisions(std::vector<long long> x)
unordered_set.hack() must not exceed 1ドル,円 000,円 000$.Note: Since the procedure hack() will be called more than once, contestants need to pay attention to the impact of the remaining data of the previous call on the current call, especially the state stored in global variables.
The cost limit of 1ドル,円 000,円 000$ applies to each test case. In general, if there are $t$ calls to hack(), you may use a total cost of no more than $t \times 1,円 000,円 000,ドル with each individual call to hack() using a cost no more than 1ドル,円 000,円 000$.
The interactor is not adaptive, i.e. the values of $n$ are fixed before the start of interaction.
Suppose, there are 2ドル$ multitests. The grader will make a following call:
hack()
Let's say, within the function, you make following calls:
| Call | Returned value |
|---|---|
collisions([2, 15, 7, 27, 8, 30]) |
4ドル$ |
collisions([1, 2, 3]) |
0ドル$ |
collisions([10, 20, 30, 40, 50]) |
10ドル$ |
After that, if you find that the value of $n$ is 5ドル,ドル the procedure hack() should return 5ドル$.
Then grader will make another call:
hack()
Let's say, within the function, you make following calls:
| Call | Returned value |
|---|---|
collisions([1, 3]) |
1ドル$ |
collisions([2, 4]) |
1ドル$ |
The only $n$ which satisfies the queries is 2ドル$. So, the procedure hack() should return 2ドル$.
collisions().| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 8 | $n ≤ 500,円 000$ |
| 2 | 17 | $n ≤ 1,円 000,円 000$ |
| 3 | 75 | No additional constraints. |
In the last subtask, you can get partial score. Let $q$ be the maximum total cost among all invocations of hack() over every test case of the subtask. Your score for this subtask is calculated according to the following table:
| Condition | Points |
|---|---|
| 1ドル,円 000,円 000 < q$ | 0ドル$ |
| 110ドル,円 000 < q ≤ 1,円 000,円 000$ | 75ドル \cdot \log_{50}{\left(\displaystyle\frac{10^6}{q−90000}\right)}$ |
| $q ≤ 110,円 000$ | 75ドル$ |
If, in any of the test cases, the calls to the procedure collisions() do not conform to the constraints described in Implementation Details, or the number returned by hack() is incorrect, the score of your solution for that subtask will be 0ドル$.
The sample grader reads the input in the following format:
Then, $t$ lines follow, each containing a value of $n$:
For each test case, let $m$ be the return value of hack(), and $c$ be the total cost of all queries. The sample grader prints your answer in the following format:
C++17, C++20, C++23, C++26, C++17 (Clang), C++20 (Clang)