题解:CF1552D Array Differentiation
首先注意到
考虑一个有
我们对于这个环上的每条边,都对应了
要是环上有反向的边,其实我们只需要把反向边对应的
所以这题就简单了,直接枚举
代码瞎写的,最好别看
#include<bits/stdc++.h>
using namespace std;
#define int long long
int fastpow(int a, int b, int mod)
{
int res = 1;
while (b) {
if (b & 1) {
res = (res * a) % mod;
}
a = (a * a) % mod;
b >>= 1;
}
return res;
}
void solve()
{
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int tp = fastpow(3, n, 1145141919810);
for (int i = 1; i < tp; i++) {
int cnt = 0;
int ttp = i;
for (int j = 0; j < n; j++) {
cnt += (ttp % 3 == 2 ? -1 : ttp % 3) * a[j];
ttp /= 3;
}
if (cnt == 0) {
cout << "YES" << '\n';
return;
}
}
cout << "NO" << '\n';
}
signed main()
{
int T;
cin >> T;
while (T--) {
solve();
}
return 0;
}