A15353 | Add Modulo 10
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given an array of $n$ integers $a_1, a_2, \dots, a_n$
You can apply the following operation an arbitrary number of times:
- select an index $i$ ( $1 \le i \le n$ ) and replace the value of the element $a_i$ with the value $a_i + (a_i \bmod 10)$ , where $a_i \bmod 10$ is the remainder of the integer dividing $a_i$ by $10$ .
For a single index (value $i$ ), this operation can be applied multiple times. If the operation is applied repeatedly to the same index, then the current value of $a_i$ is taken into account each time. For example, if $a_i=47$ then after the first operation we get $a_i=47+7=54$ , and after the second operation we get $a_i=54+4=58$ .
Check if it is possible to make all array elements equal by applying multiple (possibly zero) operations.
For example, you have an array $[6, 11]$ .
- Let's apply this operation to the first element of the array. Let's replace $a_1 = 6$ with $a_1 + (a_1 \bmod 10) = 6 + (6 \bmod 10) = 6 + 6 = 12$ . We get the array $[12, 11]$ .
- Then apply this operation to the second element of the array. Let's replace $a_2 = 11$ with $a_2 + (a_2 \bmod 10) = 11 + (11 \bmod 10) = 11 + 1 = 12$ . We get the array $[12, 12]$ .
Thus, by applying $2$ operations, you can make all elements of an array equal.
You can apply the following operation an arbitrary number of times:
- select an index $i$ ( $1 \le i \le n$ ) and replace the value of the element $a_i$ with the value $a_i + (a_i \bmod 10)$ , where $a_i \bmod 10$ is the remainder of the integer dividing $a_i$ by $10$ .
For a single index (value $i$ ), this operation can be applied multiple times. If the operation is applied repeatedly to the same index, then the current value of $a_i$ is taken into account each time. For example, if $a_i=47$ then after the first operation we get $a_i=47+7=54$ , and after the second operation we get $a_i=54+4=58$ .
Check if it is possible to make all array elements equal by applying multiple (possibly zero) operations.
For example, you have an array $[6, 11]$ .
- Let's apply this operation to the first element of the array. Let's replace $a_1 = 6$ with $a_1 + (a_1 \bmod 10) = 6 + (6 \bmod 10) = 6 + 6 = 12$ . We get the array $[12, 11]$ .
- Then apply this operation to the second element of the array. Let's replace $a_2 = 11$ with $a_2 + (a_2 \bmod 10) = 11 + (11 \bmod 10) = 11 + 1 = 12$ . We get the array $[12, 12]$ .
Thus, by applying $2$ operations, you can make all elements of an array equal.
输入格式
The first line contains one integer $t$ ( $1 \le t \le 10^4$ ) — the number of test cases. What follows is a description of each test case.
The first line of each test case contains one integer $n$ ( $1 \le n \le 2 \cdot 10^5$ ) — the size of the array.
The second line of each test case contains $n$ integers $a_i$ ( $0 \le a_i \le 10^9$ ) — array elements.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ .
The first line of each test case contains one integer $n$ ( $1 \le n \le 2 \cdot 10^5$ ) — the size of the array.
The second line of each test case contains $n$ integers $a_i$ ( $0 \le a_i \le 10^9$ ) — array elements.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ .
输出格式
For each test case print:
- YES if it is possible to make all array elements equal;
- NO otherwise.
You can print YES and NO in any case (for example, the strings yEs, yes, Yes and YES will be recognized as a positive answer) .
- YES if it is possible to make all array elements equal;
- NO otherwise.
You can print YES and NO in any case (for example, the strings yEs, yes, Yes and YES will be recognized as a positive answer) .
输入输出样例
输入 #1
10 2 6 11 3 2 18 22 5 5 10 5 10 5 4 1 2 4 8 2 4 5 3 93 96 102 2 40 6 2 50 30 2 22 44 2 1 5
输出 #1
Yes No Yes Yes No Yes No No Yes No
The first test case is clarified above.
In the second test case, it is impossible to make all array elements equal.
In the third test case, you need to apply this operation once to all elements equal to $5$ .
In the fourth test case, you need to apply this operation to all elements until they become equal to $8$ .
In the fifth test case, it is impossible to make all array elements equal.
In the sixth test case, you need to apply this operation to all elements until they become equal to $102$ .
In the second test case, it is impossible to make all array elements equal.
In the third test case, you need to apply this operation once to all elements equal to $5$ .
In the fourth test case, you need to apply this operation to all elements until they become equal to $8$ .
In the fifth test case, it is impossible to make all array elements equal.
In the sixth test case, you need to apply this operation to all elements until they become equal to $102$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted