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

33770번 - More Cow Photos 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB138847466.071%

문제

The cows are in a particularly mischievous mood today! All Farmer John wants to do is take a photograph of the cows standing in a line, but they keep moving right before he has a chance to snap the picture.

Specifically, each of FJ's $N$ cows $(1 \le N \le 10^5)$ has an integer height from 1ドル$ to $N$. FJ wants to take a picture of the cows standing in line in a very specific ordering. If the cows have heights $h_1, \dots, h_K$ when lined up from left to right, he wants the cow heights to have the following three properties:

  • He wants the cow heights to increase and then decrease. Formally, there must exist an integer $i$ such that $h_1 \le \dots \le h_i \ge \dots \ge h_K$.
  • He does not want any cow standing next to another cow with exactly the same height. Formally, $h_i \neq h_{i+1}$ for all 1ドル \le i < K$.
  • He wants the picture to be symmetric. Formally, if $i + j = K+1,ドル then $h_i = h_j$.

FJ wants the picture to contain as many cows as possible. Specifically, FJ can remove some cows and rearrange the remaining ones. Compute the maximum number of cows FJ can have in the picture satisfying his constraints.

입력

You have to answer multiple test cases.

The first line of input contains a single integer $T$ (1ドル \leq T \leq 10^5$) denoting the number of test cases. $T$ test cases follow.

The first line of every test case contains a single integer $N$. The second line of every test case contains $N$ integers, the heights of the $N$ cows available. The cow heights will be between 1ドル$ and $N$.

It is guaranteed the sum of $N$ over all test cases will not exceed 10ドル^6$.

출력

Output $T$ lines, the $i$'th line containing the answer to the $i$'th test case. Each line should be an integer denoting the maximum number of cows FJ can include in the picture.

제한

예제 입력 1

2
4
1 1 2 3
4
3 3 2 1

예제 출력 1

3
1

For the first test case, FJ can take the cows with heights 1ドル,ドル 1ドル,ドル and 3ドル,ドル and rearrange them into $[1,3,1],ドル which satisfies all the conditions. For the second test case, FJ can take the cow with height 3ドル$ and form a valid photo.

힌트

출처

Olympiad > USA Computing Olympiad > 2024-2025 Season > USACO 2025 US Open Contest > Bronze 2번

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

출처

대학교 대회

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

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