Codeforces Round 1073 (Div. 2)
B
MEX Reordering
Codeforces
1000
原题
← AC →
翻译中…

You are given an integer array $a$ consisting of $n$ elements. Denote $f(l, r) = \operatorname{MEX}([a_l, a_{l + 1}, \ldots, a_r])$$^{\text{∗}}$.

翻译中…

Determine if there is a way to reorder the array $a$ such that for every $i$ ($1 \le i \le n - 1$), $f(1, i) \neq f(i + 1, n)$. In other words, for every split point $i$, the $\operatorname{MEX}$ of the prefix must be different from the $\operatorname{MEX}$ of the suffix.

翻译中…

$^{\text{∗}}$The minimum excluded (MEX) of a collection of integers $c_1, c_2, \ldots, c_k$ is defined as the smallest non-negative integer $x$ which does not occur in the collection $c$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 500$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($2 \le n \le 100$) — the length of the array.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le n$).

翻译中…

Output

翻译中…

Output "YES" if you can reorder $a$ so that the condition from the statement is satisfied, and "NO" otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

翻译中…

Note

翻译中…

In the first example, the initial ordering of $a$ already satisfies the condition. The only choice for $i$ is $i = 1$. Then $f(1, i) = f(1, 1) = \operatorname{MEX}([a_1]) = \operatorname{MEX}([1]) = 0$, and $f(i + 1, n) = f(2, 2) = \operatorname{MEX}([a_2]) = \operatorname{MEX}([0]) = 1$. Since $0 \neq 1$, the condition is satisfied.

翻译中…

In the second example, it can be shown that there is no way to reorder $a$ to satisfy the condition. As an example, consider the order $a = [3, 0, 0]$ and $i = 2$. We have $f(1, i) = f(1, 2) = \operatorname{MEX}([a_1, a_2]) = \operatorname{MEX}([3, 0]) = 1$, and $f(i + 1, n) = f(3, 3) = \operatorname{MEX}([a_3]) = \operatorname{MEX}([0]) = 1$, hence $f(1, i) = f(i + 1, n)$, so the choice of reordering is invalid.

翻译中…

In the third example, we can reorder $a$ into $[1, 6, 1, 0, 0, 5]$. When $i = 4$, $f(1, i) = f(1, 4) = \operatorname{MEX}([a_1, a_2, a_3, a_4]) = \operatorname{MEX}([1, 6, 1, 0]) = 2$, $f(i + 1, n) = f(5, 6) = \operatorname{MEX}([a_5, a_6]) = \operatorname{MEX}([0, 5]) = 1$, so the condition is satisfied for this $i$. It can be verified that the condition is also satisfied for all other $i$.

翻译中…

样例

Input #1
3
2
1 0
3
0 3 0
6
1 0 5 0 6 1
Output #1
YES
NO
YES
InputCopy OutputCopy
题目信息
题号
2191B
时间限制
1 s
内存限制
256 MB
标签
构造
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。