cf1714E.
思路在注释里,这是大佬的思路,相比之下我的一堆if太蠢了。所以思维题总是相不出来,或者想出来也要做好久,唉。
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
using namespace std;
string s;
#define maxn 100
#define ll long long
//#define int long long
struct node {
int a, b;
};
//1 2 4 8 6 2
//2 4 8 6 2
//3 6 2 4 8 6
//4 8 6 2 4
//5 0
//6 2 4 8 6
//7 4 8 6 2 4
//8 6 2 4 8
//9 8 6 2 4 8
// 7 9
// | |
//规律如图: 1->2->4->8->6<-3
// |________|
//
// 5<->0
//中间的循环2468正好是20,因此只要他们取余20结果一样,那就可以统一化成个位数是2的,这样取余20直接判断是否相等即可
//至于5,0特判即可,这个只要是有且不全是,那就肯定没法一样。
void solve()
{
int ans = 0;
int n;
cin >> n;
int a[maxn];
int flag5 = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
if (a[i] % 5 == 0)
flag5++;
}
if (flag5 > 0 && flag5 < n)
{
cout << "NO" << endl;
return;
}
for (int i = 1; i <= n; i++)
{
while (a[i] % 10 != 2 && a[i] % 10 != 0)
a[i] += a[i] % 10;
}
if (flag5 == 0)
for (int i = 1; i <= n; i++)
{
a[i] %= 20;
}
for (int i = 2; i <= n; i++)
if (a[i] != a[i - 1])
{
cout << "NO" << endl;
return;
}
cout << "YES" << endl;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}