Atto Round 1 (Codeforces Round 1041, Div. 1 + Div. 2)
A
Mix Mex Max
Codeforces
800
原题
←B →
翻译中…

You are given an array $a$ consisting of $n$ non-negative integers. However, some elements of $a$ are missing, and they are represented by $−1$.

翻译中…

We define that the array $a$ is good if and only if the following holds for every $1 \leq i \leq n-2$:

翻译中…

$$ \operatorname{mex}([a_i, a_{i+1}, a_{i+2}]) = \max([a_i, a_{i+1}, a_{i+2}]) - \min([a_i, a_{i+1}, a_{i+2}]), $$

翻译中…

where $\operatorname{mex}(b)$ denotes the minimum excluded (MEX)$^{\text{∗}}$ of the integers in $b$.

翻译中…

You have to determine whether you can make $a$ good after replacing each $-1$ in $a$ with a non-negative integer.

翻译中…

$^{\text{∗}}$The minimum excluded (MEX) of a collection of integers $b_1, b_2, \ldots, b_k$ is defined as the smallest non-negative integer $x$ which does not occur in the collection $b$. For example, $\operatorname{mex}([2,2,1])=0$ because $0$ does not belong to the array, and $\operatorname{mex}([0,3,1,2])=4$ because $0$, $1$, $2$, and $3$ appear in the array, but $4$ does not.

翻译中…

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$ ($3 \leq n \leq 100$) — the length of $a$.

翻译中…

The second line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($-1 \leq a_i \leq 100$) — the elements of $a$. $a_i = -1$ denotes that this element is missing.

翻译中…

Output

翻译中…

For each test case, output "YES" if it is possible to make $a$ good, 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 test case, we can put $ a_1 = a_2 = a_3 = 1 $. Then,

翻译中…
  • $\operatorname{mex}([a_1, a_2, a_3]) = \operatorname{mex}([1, 1, 1]) = 0$;
  • $\max([a_1, a_2, a_3]) = \max([1, 1, 1]) = 1$;
  • $\min([a_1, a_2, a_3]) = \min([1, 1, 1]) = 1$.
翻译中…

And $0 = 1 - 1$. Thus, the array $a$ is good.

翻译中…

In the second test case, none of the elements in $a$ is missing. And we have

翻译中…
  • $\operatorname{mex}([a_1, a_2, a_3]) = \max([a_1, a_2, a_3]) - \min([a_1, a_2, a_3])$,
  • $\operatorname{mex}([a_2, a_3, a_4]) = \max([a_2, a_3, a_4]) - \min([a_2, a_3, a_4])$, but
  • $\operatorname{mex}([a_3, a_4, a_5]) \ne \max([a_3, a_4, a_5]) - \min([a_3, a_4, a_5])$.
翻译中…

Thus, the array $a$ cannot be good.

翻译中…

In the third test case, none of $a_1$, $a_2$, or $a_3$ is missing. However,

翻译中…
  • $\operatorname{mex}([a_1, a_2, a_3]) = \operatorname{mex}([5, 5, 1]) = 0$;
  • $\max([a_1, a_2, a_3]) = \max([5, 5, 1]) = 5$;
  • $\min([a_1, a_2, a_3]) = \min([5, 5, 1]) = 1$.
翻译中…

And $0\ne 5 - 1$. So the array $a$ cannot be good, no matter how you replace the missing elements.

翻译中…

样例

Input #1
8
3
-1 -1 -1
5
1 1 1 1 0
6
5 5 1 -1 -1 1
4
-1 -1 0 -1
4
-1 1 1 -1
3
3 3 -1
5
0 0 0 0 0
7
3 0 1 4 -1 2 3
Output #1
YES
NO
NO
NO
YES
YES
NO
NO
InputCopy OutputCopy
题目信息
题号
2127A
时间限制
1 s
内存限制
256 MB
标签
构造
贪心
数学

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