欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2127A.Mix Mex Max
Mix Mex Max
You are given an array consisting of non-negative integers. However, some elements of are missing, and they are represented by .
We define that the array is good if and only if the following holds for every :
$$\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}]),$$</p><p>where$\operatorname{mex}(b)$denotes the minimum excluded (MEX)$^{\text{∗}}$of the integers in$b$. </p><p>You have to determine whether you can make$a$<span class="tex-font-style-it">good</span> after replacing each$-1$in$a$with a non-negative integer.</p><div class="statement-footnote"><p>$^{\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. ## Samples ```input1 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 ``` ```output1 YES NO NO NO YES YES NO NO ```$$在线编程 IDE
建议全屏模式获得最佳体验
键盘快捷键
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |
第 1 行,第 1 列
0 字符
-
最近自测结果
暂未运行
最近递交结果
暂无递交记录