CF2247A.Zero Sum
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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:
- Choose an index i satisfying 1≤i≤n−1.
- Assign ai=−ai and ai+1=−ai+1.
Determine whether it is possible to make the sum of elements of a equal to 0.
给你一个长度为 n 的数组 a,其中每个元素仅为 −1 或 1。
你可以对 a 执行以下操作任意多次:
- 选择一个满足 1≤i≤n−1 的下标 i;
- 将 ai 和 ai+1 同时取反(即令 ai=−ai 且 ai+1=−ai+1)。
判断是否可能通过若干次操作使得数组 a 中所有元素的和等于 0。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤200). The description of the test cases follows.
The first line of each test case contains a single integer n (1≤n≤100) — the length of array a.
The second line of each test case contains n integers a1,a2,…,an (ai∈−1,1) — the array a.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤200)。随后是测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤100)—— 数组 a 的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(其中 ai∈{−1,1})—— 数组 a。
输出格式
For each test case, print "YES" if it is possible to make the sum of elements of a equal to 0, 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.
对于每个测试用例,如果可以使数组 a 的元素之和等于 0,则输出 "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 a equals −1=0, so the answer is "NO".
In the second example, the sum of elements of a is already 0, so the answer is "YES".
In the fifth example, we can perform an operation with i=3, transforming a as follows: [−1,1,−1,−1,−1,−1]→[−1,1,1,1,−1,−1]. The sum of the resulting array is 0, so the answer is "YES".
在第一个例子中,我们无法执行任何操作,且数组 a 的元素和为 −1=0,因此答案是 “NO”。
在第二个例子中,数组 a 的元素和已经为 0,因此答案是 “YES”。
在第五个例子中,我们可以对 i=3 执行一次操作,将 a 变换如下:[−1,1,−1,−1,−1,−1]→[−1,1,1,1,−1,−1]。变换后数组的和为 0,因此答案是 “YES”。
输入解题思路,AI测评打分。不知道怎么写?