CodeForces - 1669C Odd/Even Increments

Given an array a=[a_1,a_2,\dots,a_n]a=[a
1

,a
2

,…,a
n

] of nn positive integers, you can do operations of two types on it:

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

:=a
1

+1,a
3

:=a
3

+1,a
5

:=a
5

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

:=a
2

+1,a
4

:=a
4

+1,a
6

:=a
6

+1,….
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.

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

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

The second line of each test case contains nn integers a_1, a_2, \dots, a_na
1

,a
2

,…,a
n

(1 \leq a_i \leq 10^31≤a
i

≤10
3
) — the elements of the array.

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

Output
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).

Sample 1
Inputcopy Outputcopy
4
3
1 2 1
4
2 2 2 3
4
2 2 2 2
5
1000 1 1000 1 1000
YES
NO
YES
YES
Note
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”.

#include<iostream>
using namespace std;
int main(){
	int t, n, a[52], b1, b2, i, flag;
	cin >> t;
	while (t--){
		flag = 0;
		cin >> n >> a[1] >> a[2];
		b1 = a[1] % 2;
		b2 = a[2] % 2;
		if (n > 2){
			for (i = 3; i <= n; i++){
				cin >> a[i];
				if (i % 2 == 1){
					if (a[i] % 2 != b1){
						flag = 1;
					}
				}else{
					if (a[i] % 2 != b2){
						flag = 1;
					}
				}
			}
		}
		if (flag == 0){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值