CF2247A.Zero Sum

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array aa of length nn, consisting only of −1-1 and 11.

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

  1. Choose an index ii satisfying 1≤i≤n−11 \le i \le n - 1.
  2. Assign ai=−aia_i = -a_i and ai+1=−ai+1a_{i + 1} = -a_{i + 1}.

Determine whether it is possible to make the sum of elements of aa equal to 00.

给你一个长度为 nn 的数组 aa,其中每个元素仅为 −1-1 或 11。

你可以对 aa 执行以下操作任意多次:

  1. 选择一个满足 1≤i≤n−11 \le i \le n - 1 的下标 ii;
  2. 将 aia_i 和 ai+1a_{i + 1} 同时取反(即令 ai=−aia_i = -a_i 且 ai+1=−ai+1a_{i + 1} = -a_{i + 1})。

判断是否可能通过若干次操作使得数组 aa 中所有元素的和等于 00。

输入格式

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

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

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (ai∈−1,1a_i \in {-1, 1}) — the array aa.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤2001 \le t \le 200)。随后是测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \le n \le 100)—— 数组 aa 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(其中 ai∈{−1,1}a_i \in \{-1, 1\})—— 数组 aa。

输出格式

For each test case, print "YES" if it is possible to make the sum of elements of aa equal to 00, 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.

对于每个测试用例,如果可以使数组 aa 的元素之和等于 00,则输出 "YES";否则输出 "NO"。

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

输入输出样例

  • 输入#1

    5
    1
    -1
    2
    1 -1
    2
    1 1
    5
    1 -1 1 -1 1
    6
    -1 1 -1 -1 -1 -1

    输出#1

    NO
    YES
    NO
    NO
    YES

说明/提示

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

In the second example, the sum of elements of aa is already 00, so the answer is "YES".

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

在第一个例子中,我们无法执行任何操作,且数组 aa 的元素和为 −1≠0-1 \neq 0,因此答案是 “NO”。

在第二个例子中,数组 aa 的元素和已经为 00,因此答案是 “YES”。

在第五个例子中,我们可以对 i=3i = 3 执行一次操作,将 aa 变换如下:[−1,1,−1,−1,−1,−1]→[−1,1,1,1,−1,−1][-1, 1, \color{red}{-1, -1}, -1, -1] \rightarrow [-1, 1, \color{red}{1, 1}, -1, -1]。变换后数组的和为 00,因此答案是 “YES”。

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

首页