CF1941B.Rudolf and 121

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Rudolf has an array aa of nn integers, the elements are numbered from 11 to nn.

In one operation, he can choose an index ii (2≤i≤n−12 \le i \le n - 1) and assign:

  • ai−1=ai−1−1a_{i - 1} = a_{i - 1} - 1
  • ai=ai−2a_i = a_i - 2
  • ai+1=ai+1−1a_{i + 1} = a_{i + 1} - 1

Rudolf can apply this operation any number of times. Any index ii can be used zero or more times.

Can he make all the elements of the array equal to zero using this operation?

鲁道夫有一个包含 nn 个整数的数组 aa,元素编号从 11 到 nn。

在一次操作中,他可以选择一个下标 ii(满足 2≤i≤n−12 \le i \le n - 1),并执行如下赋值:

  • ai−1=ai−1−1a_{i - 1} = a_{i - 1} - 1
  • ai=ai−2a_i = a_i - 2
  • ai+1=ai+1−1a_{i + 1} = a_{i + 1} - 1

鲁道夫可以执行该操作任意多次。任意下标 ii 均可被使用零次或多次。

他能否通过该操作将数组的所有元素都变为零?

输入格式

The first line of the input contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases in the test.

The first line of each case contains a single integer nn (3≤n≤2⋅1053 \le n \le 2 \cdot 10^5) — the number of elements in the array.

The second line of each case contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤aj≤1090 \le a_j \le 10^9) — the elements of the array.

It is guaranteed that the sum of the values of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

每个测试用例的第一行包含一个整数 nn(3≤n≤2⋅1053 \le n \le 2 \cdot 10^5)—— 表示数组中元素的个数。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤aj≤1090 \le a_j \le 10^9)—— 表示数组的元素。

保证所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output "YES" if it is possible to make all the elements of the array zero using the described operations. Otherwise, output "NO".

You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.

对于每个测试用例,如果可以使用所描述的操作将数组的所有元素变为零,则输出 “YES”;否则输出 “NO”。

你可以以任意大小写形式输出每个字母(小写或大写)。例如,字符串 “yEs”、“yes”、“Yes” 和 “YES” 均被视为正确答案。

输入输出样例

  • 输入#1

    7
    5
    1 3 5 5 2
    5
    2 4 4 5 1
    5
    0 1 3 3 1
    6
    5 6 0 2 3 0
    4
    1 2 7 2
    3
    7 1 0
    4
    1 1 1 1

    输出#1

    YES
    NO
    YES
    NO
    NO
    NO
    NO

说明/提示

In the first example, the original array is [1,3,5,5,2][1, 3, 5, 5, 2], to make all its elements zero, Rudolf can act as follows:

  • apply the operation at i=4i=4 and get the array [1,3,4,3,1][1, 3, 4, 3, 1];
  • apply the operation at i=3i=3 and get the array [1,2,2,2,1][1, 2, 2, 2, 1];
  • apply the operation at i=2i=2 and get the array [0,0,1,2,1][0, 0, 1, 2, 1];
  • apply the operation at i=4i=4 and get the array [0,0,0,0,0][0, 0, 0, 0, 0].

在第一个例子中,原始数组为 [1,3,5,5,2][1, 3, 5, 5, 2]。为了将所有元素变为零,Rudolf 可以按如下方式操作:

  • 在位置 i=4i=4 执行操作,得到数组 [1,3,4,3,1][1, 3, 4, 3, 1];
  • 在位置 i=3i=3 执行操作,得到数组 [1,2,2,2,1][1, 2, 2, 2, 1];
  • 在位置 i=2i=2 执行操作,得到数组 [0,0,1,2,1][0, 0, 1, 2, 1];
  • 在位置 i=4i=4 执行操作,得到数组 [0,0,0,0,0][0, 0, 0, 0, 0]。

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

首页