Codeforces Round 1111 (Div. 2)
A
零和
Zero Sum
Codeforces
800
原题
←B →

零和AI (CI翻译)

You are given an array $a$ of length $n$, consisting only of $-1$ and $1$.

翻译中…

You may perform the following operation on $a$ any number of times:

翻译中…
  1. Choose an index $i$ satisfying $1 \le i \le n - 1$.
  2. Assign $a_i = -a_i$ and $a_{i + 1} = -a_{i + 1}$.
翻译中…

Determine whether it is possible to make the sum of elements of $a$ equal to $0$.

翻译中…

Input

输入格式

AI (CI翻译)

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 200$). The description of the test cases follows.

每个测试包含多组测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 200$)。接下来是各测试用例的描述。AI (CI翻译)

The first line of each test case contains a single integer $n$ ($1 \le n \le 100$) — the length of array $a$.

每个测试用例的第一行包含一个整数 $n$($1 \le n \le 100$),表示数组 $a$ 的长度。AI (CI翻译)

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($a_i \in \{-1, 1\}$) — the array $a$.

每个测试用例的第二行包含 $n$ 个整数 $a_1, a_2, \ldots, a_n$($a_i \in \{-1, 1\}$),表示数组 $a$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, print "YES" if it is possible to make the sum of elements of $a$ equal to $0$, and "NO" otherwise.

对于每个测试用例,如果可以使数组 $a$ 中所有元素之和等于 $0$,输出“YES”,否则输出“NO”。AI (CI翻译)

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”、“yes”、“Yes”和“YES”都会被识别为肯定 პასუხ。AI (CI翻译)

Note

说明

AI (CI翻译)

In the first example, we cannot perform any operations, and the sum of elements of $a$ equals $-1 \neq 0$, so the answer is "NO".

在第一个样例中,我们无法执行任何操作,并且数组 $a$ 中所有元素之和为 $-1 \neq 0$,因此答案为“NO”。AI (CI翻译)

In the second example, the sum of elements of $a$ is already $0$, so the answer is "YES".

在第二个样例中,数组 $a$ 中所有元素之和已经为 $0$,因此答案为“YES”。AI (CI翻译)

In the fifth example, we can perform an operation with $i = 3$, transforming $a$ as follows: $[-1, 1, \color{red}{-1, -1}, -1, -1] \rightarrow [-1, 1, \color{red}{1, 1}, -1, -1]$. The sum of the resulting array is $0$, so the answer is "YES".

在第五个样例中,我们可以选择 $i = 3$ 执行一次操作,将 $a$ 变换如下:$[-1, 1, \color{red}{-1, -1}, -1, -1] \rightarrow [-1, 1, \color{red}{1, 1}, -1, -1]$。变换后数组的元素之和为 $0$,因此答案为“YES”。AI (CI翻译)

样例

Input #1
5
1
-1
2
1 -1
2
1 1
5
1 -1 1 -1 1
6
-1 1 -1 -1 -1 -1
Output #1
NO
YES
NO
NO
YES
InputCopy OutputCopy
题目信息
题号
2247A
时间限制
1 s
内存限制
256 MB
标签
构造
动态规划
数论

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