CF1669C.Odd/Even Increments

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Given an array a=[a1,a2,…,an]a=[a_1,a_2,\dots,a_n] of nn positive integers, you can do operations of two types on it:

  1. Add 11 to every element with an odd index. In other words change the array as follows: a1:=a1+1,a3:=a3+1,a5:=a5+1,…a_1 := a_1 +1, a_3 := a_3 + 1, a_5 := a_5+1, \dots.

  2. Add 11 to every element with an even index. In other words change the array as follows: a2:=a2+1,a4:=a4+1,a6:=a6+1,…a_2 := a_2 +1, a_4 := a_4 + 1, a_6 := a_6+1, \dots.

Determine if after any number of operations it is possible to make the final array contain only even numbers or only odd numbers. In other words, determine if you can make all elements of the array have the same parity after any number of operations.

Note that you can do operations of both types any number of times (even none). Operations of different types can be performed a different number of times.

给定一个包含 nn 个正整数的数组 a=[a1,a2,…,an]a=[a_1,a_2,\dots,a_n],你可以对它执行以下两种操作:

  1. 将所有奇数下标位置的元素加 11。即按如下方式修改数组:a1:=a1+1,a3:=a3+1,a5:=a5+1,…a_1 := a_1 +1, a_3 := a_3 + 1, a_5 := a_5+1, \dots。

  2. 将所有偶数下标位置的元素加 11。即按如下方式修改数组:a2:=a2+1,a4:=a4+1,a6:=a6+1,…a_2 := a_2 +1, a_4 := a_4 + 1, a_6 := a_6+1, \dots。

判断:经过任意次数的操作后,是否可能使最终数组中的所有元素均为偶数,或均为奇数?换言之,判断是否能通过任意次数的操作,使得数组中所有元素具有相同的奇偶性。

注意:你可以对两种操作各自执行任意次数(包括零次),且两种操作的执行次数可以不同。

输入格式

The first line contains an integer tt (1≤t≤1001 \leq t \leq 100) — the number of test cases.

The first line of each test case contains an integer nn (2≤n≤502 \leq n \leq 50) — the length of the array.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1031 \leq a_i \leq 10^3) — the elements of the array.

Note that after the performed operations the elements in the array can become greater than 10310^3.

第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100)—— 表示测试用例的数量。

每个测试用例的第一行包含一个整数 nn(2≤n≤502 \leq n \leq 50)—— 表示数组的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1031 \leq a_i \leq 10^3)—— 表示数组的元素。

注意:执行操作后,数组中的元素可能大于 10310^3。

输出格式

Output tt lines, each of which contains the answer to the corresponding test case. As an answer, output "YES" if after any number of operations it is possible to make the final array contain only even numbers or only odd numbers, and "NO" otherwise.

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

输出 tt 行,每行包含对应测试用例的答案。若经过任意次数的操作后,最终数组可以只包含偶数或只包含奇数,则输出 "YES";否则输出 "NO"。

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

输入输出样例

  • 输入#1

    4
    3
    1 2 1
    4
    2 2 2 3
    4
    2 2 2 2
    5
    1000 1 1000 1 1000

    输出#1

    YES
    NO
    YES
    YES

说明/提示

For the first test case, we can increment the elements with an even index, obtaining the array [1,3,1][1, 3, 1], which contains only odd numbers, so the answer is "YES".

For the second test case, we can show that after performing any number of operations we won't be able to make all elements have the same parity, so the answer is "NO".

For the third test case, all elements already have the same parity so the answer is "YES".

For the fourth test case, we can perform one operation and increase all elements at odd positions by 11, thus obtaining the array [1001,1,1001,1,1001][1001, 1, 1001, 1, 1001], and all elements become odd so the answer is "YES".

对于第一个测试用例,我们可以对偶数下标位置的元素执行加一操作,得到数组 [1,3,1][1, 3, 1],该数组所有元素均为奇数,因此答案为 "YES"。

对于第二个测试用例,可以证明:无论执行多少次操作,都无法使所有元素具有相同的奇偶性,因此答案为 "NO"。

对于第三个测试用例,所有元素初始即具有相同的奇偶性,因此答案为 "YES"。

对于第四个测试用例,我们可以执行一次操作,将所有奇数位置(即下标为奇数)上的元素均加 11,从而得到数组 [1001,1,1001,1,1001][1001, 1, 1001, 1, 1001],此时所有元素均为奇数,因此答案为 "YES"。

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

首页