// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
using ll = long long;
template<class T> using V = vector<T>;
using vi = V<int>;
using vl = V<ll>;
const int K = 3;
array<int, K> MOD = {int(1e9) + 7, int(1e9) + 9, 1009};
array<ll, K> EMP = {0, 0, 0};
int main() {
cin.tie(0)->sync_with_stdio(0);
int N; cin >> N;
vl A(N); for(int i = 0; i < N; i++) {
ll x; cin >> x; A[i] = x;
cin >> x; A[i] -= x;
}
auto POW = [&](ll a, ll p, int m) {
ll ans = 1;
for(; p; p /= 2, a = (a * a) % m) if (p % 2) ans = (ans * a) % m;
return ans;
};
auto ADD = [&](ll &a, ll b, int m) { return (a + b) % m; };
auto SUB = [&](ll &a, ll b, int m) { return (a - b + m) % m; };
auto MUL = [&](ll &a, ll b, int m) { return (a * b) % m; };
array<ll, K> cur = {0, 0, 0};
for(int i = N - 1; i >= 0; i--) {
for(int k = 0; k < K; k++) cur[k] = ADD(cur[k], MUL(A[i], POW(2, N - 1 - i, MOD[k]), MOD[k]), MOD[k]);
}
bool ans = (cur == EMP);
for(int i = 0; i < N; i++) {
for(int k = 0; k < K; k++) {
cur[k] = SUB(cur[k], MUL(A[i], POW(2, N - 1, MOD[k]), MOD[k]), MOD[k]);
cur[k] = MUL(cur[k], 2, MOD[k]);
cur[k] = ADD(cur[k], A[i], MOD[k]);
}
ans |= (cur == EMP);
}
cout << (ans ? "Yes" : "No") << nl;
exit(0-0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |