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

27459번 - Adjacent Pairs 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 1024 MB134212121.875%

문제

Let's call an array $b_1, b_2, \dots , b_m$ good, if $b_i ≠ b_{i+1}$ for any $i$ with 1ドル ≤ i ≤ m - 1$.

You are given a good array of $n$ positive integers $a_1, a_2 , a_3 , \dots , a_n$.

You can perform the following operations on this array:

Choose any index $i$ (1ドル ≤ i ≤ n$) and a number $x$ (1ドル ≤ x ≤ 10^9$). Then, set $a_i$ to $x$. After this operation, the array has to remain good.

You want to perform several operations so that the resulting array will contain exactly two distinct values. Determine the smallest number of operations needed to achieve this goal.

입력

The first line of input contains the integer $t$ (1ドル ≤ t ≤ 10^5$), the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer $n$ (2ドル ≤ n ≤ 2 ⋅ 10^5$) - the length of the array.

The second line of each test case contains $n$ integers $a_1 , a_2 , \dots , a_n$ (1ドル ≤ a_i ≤ n$) - elements of the array. It's guaranteed that $a_i ≠ a_{i+1}$ for 1ドル ≤ i ≤ n - 1$ (that is, the array is good).

It is guaranteed that the sum of n over all test cases does not exceed 2ドル ⋅ 10^5$.

출력

For each test case, output a single integer - the smallest number of operations needed to achieve an array in which there are exactly two distinct values.

제한

서브태스크

번호배점제한
120

The sum of $n$ over all test cases does not exceed 100ドル$

210

The sum of $n$ over all test cases does not exceed 500ドル$

325

The sum of $n$ over all test cases does not exceed 4000ドル$

445

No additional constraints

예제 입력 1

2
5
4 5 2 4 5
2
1 2

예제 출력 1

3
0

노트

In the first test case, one of the optimal sequences of operations is:

$(4, 5, 2, 4, 5) → (2, 5, 2, 4, 5) → (2, 5, 2, 4, 2) → (2, 5, 2, 5, 2)$.

In the second test case, the array already contains only two distinct values, so the answer is 0ドル$.

출처

Olympiad > European Junior Olympiad in Informatics > eJOI 2022 1번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
  • 이 문제의 채점 우선 순위는 2이다.
(追記) (追記ここまで)

출처

대학교 대회

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

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