CF1836A.Destroyer

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

John is a lead programmer on a destroyer belonging to the space navy of the Confederacy of Independent Operating Systems. One of his tasks is checking if the electronic brains of robots were damaged during battles.

A standard test is to order the robots to form one or several lines, in each line the robots should stand one after another. After that, each robot reports the number of robots standing in front of it in its line.

An example of robots' arrangement (the front of the lines is on the left). The robots report the numbers above.

The ii-th robot reported number lil_i. Unfortunately, John does not know which line each robot stands in, and can't check the reported numbers. Please determine if it is possible to form the lines in such a way that all reported numbers are correct, or not.

约翰是独立操作系统联邦太空海军一艘驱逐舰的首席程序员。他的任务之一是检查机器人在战斗中电子大脑是否受损。

一种标准测试方法是命令机器人排成一行或多行,每行中机器人需一个接一个地站立。之后,每个机器人报告其所在行中位于它前方的机器人数量。

机器人的一个排列示例(各行的前方在左侧)。机器人报告的数字标于上方。

第 ii 个机器人报告的数字为 lil_i。遗憾的是,约翰并不知道每个机器人位于哪一行,也无法核实所报告的数字。请判断:是否存在一种排成行的方式,使得所有报告的数字均正确?

输入格式

The first line contains a single integer tt (1≤t≤1001 \leq t \leq 100), denoting the number of test cases.

The first line in each test case contains a single integer nn (1≤n≤1001 \le n \le 100) — the number of robots.

The second line in each test case contains nn integers l1,l2,…,lnl_1, l_2, \ldots, l_n (0≤li<1000 \leq l_i \lt 100), lil_i is equal to the number of robots in front of the ii-th robot in its line.

The sum of nn over all test cases won't exceed 200200.

第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100),表示测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \le n \le 100)—— 表示机器人的数量。

每个测试用例的第二行包含 nn 个整数 l1,l2,…,lnl_1, l_2, \ldots, l_n(0≤li<1000 \leq l_i \lt 100),其中 lil_i 表示第 ii 个机器人在其所在队列中前面的机器人数量。

所有测试用例的 nn 之和不超过 200200。

输出格式

For each test case, output "YES", if there exists a robot arrangement consistent with robots' reports. Otherwise, output "NO".

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.

对于每个测试用例,如果存在一种机器人排列方式与所有机器人的报告一致,则输出 “YES”;否则输出 “NO”。

你可以以任意大小写形式输出答案(大写或小写均可)。例如,字符串 “yEs”、“yes”、“Yes” 和 “YES” 均会被识别为肯定回答。

输入输出样例

  • 输入#1

    5
    6
    0 1 2 0 1 0
    9
    0 0 0 0 1 1 1 2 2
    3
    0 0 2
    1
    99
    5
    0 1 2 3 4

    输出#1

    YES
    YES
    NO
    NO
    YES

说明/提示

Example arrangement consistent with robot statements from the first example test case:

Example arrangement consistent with robot statements from the second example is shown in the statement.

In the third test case, the third robot claims that there are two machines in front of it. In such a case, the robot directly in front of it would have one machine in front. No robot claims that, so there is no valid arrangement.

第一个样例测试用例中,与机器人陈述一致的排列示例如下:

第二个样例测试用例中,与机器人陈述一致的排列如题面所示。

在第三个测试用例中,第三个机器人声称其前方有两台机器。此时,紧邻它前方的机器人前方将恰好有一台机器。但没有任何机器人作出该声明,因此不存在合法的排列。

输入解题思路,AI测评打分。不知道怎么写?

首页