A15020 | Odd/Even Increments
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Given an array $a=[a_1,a_2,\dots,a_n]$ of $n$ positive integers, you can do operations of two types on it:
1. Add $1$ 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, \dots$ .
2. Add $1$ 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, \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.
1. Add $1$ 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, \dots$ .
2. Add $1$ 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, \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.
输入格式
The first line contains an integer $t$ ( $1 \leq t \leq 100$ ) — the number of test cases.
The first line of each test case contains an integer $n$ ( $2 \leq n \leq 50$ ) — the length of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \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 $10^3$ .
The first line of each test case contains an integer $n$ ( $2 \leq n \leq 50$ ) — the length of the array.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \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 $10^3$ .
输出格式
Output $t$ 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).
You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
输入输出样例
输入 #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]$ , 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 $1$ , thus obtaining the array $[1001, 1, 1001, 1, 1001]$ , and all elements become odd 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 $1$ , thus obtaining the array $[1001, 1, 1001, 1, 1001]$ , and all elements become odd so the answer is "YES".
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted