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

26114번 - SubsetMex 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB46373389.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:

  1. Choose a (possibly empty) subset T of S. Here, T is a set of distinct numbers that appear in S.
  2. Erase elements of T from S. (Remove only one copy of each element.)
  3. Insert mex(T) into S, where mex(T) is the smallest non-negative integer that does not belong to T. The name mex stands for “minimum excluded” value.

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:

  • The first line of each test case contains a single integer n (1 ≤ n ≤ 50), representing the integer to be inserted into S.
  • The second line of each test case contains n integers f0, f1, …, fn−1 (0 ≤ fi ≤ 1016), representing the multiset S as mentioned above.

출력

For each test case, print a single line containing the minimum number of operations needed to satisfy the condition.

제한

서브태스크

번호배점제한
15

n ≤ 2

217

n ≤ 20

37

fi = 0

49

fi ≤ 1

520

fi ≤ 2000

69

f0 ≤ 1016 and fj = 0 (for all j ≠ 0)

710

There exists a value i for which fi ≤ 1016 and fj = 0 (for all j ≠ i)

823

No additional constraints

예제 입력 1

2
4
0 3 0 3
5
4 1 0 2 0

예제 출력 1

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:

  1. choose T = {} then S becomes {0, 1, 1, 1, 3, 3, 3}
  2. choose T = {0, 1, 3} then S becomes {1, 1, 2, 3, 3}
  3. choose T = {1} then S becomes {0, 1, 2, 3, 3}
  4. choose T = {0, 1, 2, 3} then S becomes {3, 4}

출처

Olympiad > European Girls' Olympiad in Informatics > EGOI 2022 > Day 1 A번

채점 및 기타 정보

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

출처

대학교 대회

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

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