CF1714E.Add Modulo 10

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array of nn integers a1,a2,…,ana_1, a_2, \dots, a_n

You can apply the following operation an arbitrary number of times:

  • select an index ii (1≤i≤n1 \le i \le n) and replace the value of the element aia_i with the value ai+(ai mod 10)a_i + (a_i \bmod 10), where ai mod 10a_i \bmod 10 is the remainder of the integer dividing aia_i by 1010.

For a single index (value ii), this operation can be applied multiple times. If the operation is applied repeatedly to the same index, then the current value of aia_i is taken into account each time. For example, if ai=47a_i=47 then after the first operation we get ai=47+7=54a_i=47+7=54, and after the second operation we get ai=54+4=58a_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][6, 11].

  • Let's apply this operation to the first element of the array. Let's replace a1=6a_1 = 6 with a1+(a1 mod 10)=6+(6 mod 10)=6+6=12a_1 + (a_1 \bmod 10) = 6 + (6 \bmod 10) = 6 + 6 = 12. We get the array [12,11][12, 11].
  • Then apply this operation to the second element of the array. Let's replace a2=11a_2 = 11 with a2+(a2 mod 10)=11+(11 mod 10)=11+1=12a_2 + (a_2 \bmod 10) = 11 + (11 \bmod 10) = 11 + 1 = 12. We get the array [12,12][12, 12].

Thus, by applying 22 operations, you can make all elements of an array equal.

给你一个包含 nn 个整数的数组 a1,a2,…,ana_1, a_2, \dots, a_n。

你可以任意次执行以下操作:

  • 选择一个下标 ii(1≤i≤n1 \le i \le n),并将元素 aia_i 的值替换为 ai+(ai mod 10)a_i + (a_i \bmod 10),其中 ai mod 10a_i \bmod 10 表示 aia_i 除以 1010 所得的余数。

对同一个下标(即同一个 ii),该操作可以执行多次。每次对同一位置重复应用该操作时,均以当前的 aia_i 值为准。例如,若 ai=47a_i = 47,则第一次操作后得到 ai=47+7=54a_i = 47 + 7 = 54,第二次操作后得到 ai=54+4=58a_i = 54 + 4 = 58。

请判断:是否可以通过执行若干次(可能为零次)上述操作,使得数组中所有元素的值相等。

例如,给定数组 [6,11][6, 11]:

  • 对数组的第一个元素执行该操作:将 a1=6a_1 = 6 替换为 a1+(a1 mod 10)=6+(6 mod 10)=6+6=12a_1 + (a_1 \bmod 10) = 6 + (6 \bmod 10) = 6 + 6 = 12,得到数组 [12,11][12, 11]。
  • 再对数组的第二个元素执行该操作:将 a2=11a_2 = 11 替换为 a2+(a2 mod 10)=11+(11 mod 10)=11+1=12a_2 + (a_2 \bmod 10) = 11 + (11 \bmod 10) = 11 + 1 = 12,得到数组 [12,12][12, 12]。

因此,通过执行 22 次操作,即可使数组所有元素相等。

输入格式

The first line contains one integer tt (1≤t≤1041 \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 nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the size of the array.

The second line of each test case contains nn integers aia_i (0≤ai≤1090 \le a_i \le 10^9) — array elements.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。随后是每个测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 数组的大小。

每个测试用例的第二行包含 nn 个整数 aia_i(0≤ai≤1090 \le a_i \le 10^9)—— 数组元素。

保证所有测试用例的 nn 之和不超过 2⋅1052 \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;
  • 否则输出 NO。

YES 和 NO 的大小写不限(例如,字符串 yEs、yes、Yes 和 YES 均被视为肯定回答)。

输入输出样例

  • 输入#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 55.

In the fourth test case, you need to apply this operation to all elements until they become equal to 88.

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 102102.

第一个测试用例已在上方说明。

第二个测试用例中,无法使数组所有元素相等。

第三个测试用例中,你需要对所有值为 55 的元素执行一次该操作。

第四个测试用例中,你需要对所有元素重复执行该操作,直至它们全部变为 88。

第五个测试用例中,无法使数组所有元素相等。

第六个测试用例中,你需要对所有元素重复执行该操作,直至它们全部变为 102102。

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

首页