CF1693A.Directional Increase

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

We have an array of length nn. Initially, each element is equal to 00 and there is a pointer located on the first element.

We can do the following two kinds of operations any number of times (possibly zero) in any order:

  1. If the pointer is not on the last element, increase the element the pointer is currently on by 11. Then move it to the next element.
  2. If the pointer is not on the first element, decrease the element the pointer is currently on by 11. Then move it to the previous element.

But there is one additional rule. After we are done, the pointer has to be on the first element.

You are given an array aa. Determine whether it's possible to obtain aa after some operations or not.

我们有一个长度为 nn 的数组。初始时,每个元素均为 00,且一个指针位于第一个元素上。

我们可以以任意顺序、任意次数(包括零次)执行以下两种操作:

  1. 若指针不在最后一个元素上,则将指针当前所指元素的值加 11,然后将指针向后移动一位(即移至下一个元素)。
  2. 若指针不在第一个元素上,则将指针当前所指元素的值减 11,然后将指针向前移动一位(即移至上一个元素)。

但还有一条额外规则:所有操作结束后,指针必须位于第一个元素上。

现给定一个数组 aa。请判断:是否可以通过若干次上述操作得到该数组 aa?

输入格式

The first line contains a single integer tt (1≤t≤1000)(1\le t\le 1000) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤2⋅105)(1\le n\le 2 \cdot 10^5) — the size of array aa.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (−109≤ai≤109-10^9 \le a_i \le 10^9) — elements of the array.

It is guaranteed that the sum of nn over all test cases doesn't exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤10001\le t\le 1000)—— 测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051\le n\le 2 \cdot 10^5)—— 数组 aa 的大小。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(−109≤ai≤109-10^9 \le a_i \le 10^9)—— 数组的元素。

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

输出格式

For each test case, print "Yes" (without quotes) if it's possible to obtain aa after some operations, and "No" (without quotes) otherwise.

You can output "Yes" and "No" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).

对于每个测试用例,如果可以通过若干次操作得到 aa,则输出 "Yes"(不带引号);否则输出 "No"(不带引号)。

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

输入输出样例

  • 输入#1

    7
    2
    1 0
    4
    2 -1 -1 0
    4
    1 -4 3 0
    4
    1 -1 1 -1
    5
    1 2 3 4 -10
    7
    2 -1 1 -2 0 0 0
    1
    0

    输出#1

    No
    Yes
    No
    No
    Yes
    Yes
    Yes

说明/提示

In the first test case we can obtain the array after some operations, but the pointer won't be on the first element.

One way of obtaining the array in the second test case is shown below.

⟨0‾,0,0,0⟩→⟨1,0‾,0,0⟩→⟨1‾,−1,0,0⟩→⟨2,−1‾,0,0⟩→⟨2,0,0‾,0⟩→⟨2,0‾,−1,0⟩→⟨2‾,−1,−1,0⟩\langle \underline{0}, 0, 0, 0\rangle \to \langle 1, \underline{0}, 0, 0 \rangle \to \langle \underline{1}, -1, 0, 0\rangle \to \langle 2, \underline{-1}, 0, 0\rangle \to \langle 2, 0, \underline{0}, 0\rangle \to \langle 2, \underline{0}, -1, 0\rangle \to \langle \underline{2}, -1, -1, 0\rangle

在第一个测试用例中,我们可以通过若干次操作得到该数组,但指针不会位于第一个元素上。

第二个测试用例中得到该数组的一种方式如下所示:

⟨0‾,0,0,0⟩→⟨1,0‾,0,0⟩→⟨1‾,−1,0,0⟩→⟨2,−1‾,0,0⟩→⟨2,0,0‾,0⟩→⟨2,0‾,−1,0⟩→⟨2‾,−1,−1,0⟩\langle \underline{0}, 0, 0, 0\rangle \to \langle 1, \underline{0}, 0, 0 \rangle \to \langle \underline{1}, -1, 0, 0\rangle \to \langle 2, \underline{-1}, 0, 0\rangle \to \langle 2, 0, \underline{0}, 0\rangle \to \langle 2, \underline{0}, -1, 0\rangle \to \langle \underline{2}, -1, -1, 0\rangle

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

首页