| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 1024 MB | 46 | 37 | 33 | 89.189% |
A multiset is a collection of elements similar to a set, where elements can repeat multiple times. For example, the following is a multiset:
{0, 0, 1, 2, 2, 5, 5, 5, 8}
Given a multiset S defined on non-negative integers, and a target non-negative integer value n such that n does not belong to S, your goal is to insert n into S by using the following 3-step operation, repeatedly:
Your goal is to find the minimum number of operations to perform so that n becomes part of S.
Since the size of S may be large, it will be given in the form of a list (f0, …, fn−1) of size n, where fi represents the number of times that the number i appears in S. (Recall that n is the integer we are trying to insert into S.)
The first line contains a single integer t (1 ≤ t ≤ 200) — the number of test cases. Each two of the following lines describe a test case:
For each test case, print a single line containing the minimum number of operations needed to satisfy the condition.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 5 | n ≤ 2 |
| 2 | 17 | n ≤ 20 |
| 3 | 7 | fi = 0 |
| 4 | 9 | fi ≤ 1 |
| 5 | 20 | fi ≤ 2000 |
| 6 | 9 | f0 ≤ 1016 and fj = 0 (for all j ≠ 0) |
| 7 | 10 | There exists a value i for which fi ≤ 1016 and fj = 0 (for all j ≠ i) |
| 8 | 23 | No additional constraints |
2 4 0 3 0 3 5 4 1 0 2 0
4 10
In the first example, initially, S = {1, 1, 1, 3, 3, 3} and our goal is to have 4 in S. We can do the following: