Logo
(追記) (追記ここまで)

34278번 - Hack! 서브태스크점수다국어언어 제한함수 구현

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 2048 MB258832.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()
  • This procedure should return an integer – the hidden value of $n$.
  • For each test case, the grader may call this function more than once. Each call should be processed as a separately new scenario.

Within this procedure, you may call the following procedure:

long long collisions(std::vector<long long> x)
  • $x$: an array of distinct numbers, where 1ドル ≤ x[i] ≤ 10^{18}$ for each $i$.
  • This function returns the number of collisions created by inserting the elements of $x$ to an unordered_set.
  • This procedure can be called multiple times. The sum of length of $x$ over all calls within one call to 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ドル$.

입력

출력

제한

  • 1ドル ≤ t ≤ 10,ドル where $t$ is the number of multitests.
  • 2ドル ≤ n ≤ 10^9$
  • 1ドル ≤ x[i] ≤ 10^{18}$ for each call to collisions().

서브태스크

번호배점제한
18

$n ≤ 500,円 000$

217

$n ≤ 1,円 000,円 000$

375

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:

  • line 1ドル$: $t$

Then, $t$ lines follow, each containing a value of $n$:

  • line 1ドル$: $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:

  • line 1ドル$: $m$ $c$

첨부

출처

Olympiad > Asia-Pacific Informatics Olympiad > APIO 2025 A번

제출할 수 있는 언어

C++17, C++20, C++23, C++26, C++17 (Clang), C++20 (Clang)

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /