RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0664

More Cow Photos

Silver III 실버 III
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

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.

Problem credits: Nick Wu

제약

SCORING

  • Inputs 2-3: \(T\le 100, N \le 7\)
  • Inputs 4-5: \(T \le 10^4\), all cows will have height at most 10.
  • Inputs 6-11: No additional constraints.

Problem credits: Nick Wu

입력 형식

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
출력
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.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2024-2025 > US Open > Bronze

태그

평가 및 의견

More Cow Photos

개요
출제자 난이도 Silver III 실버 III 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

More Cow Photos

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8