#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)
const int MN = 1000005;
int n;
pii a[MN * 2];
int fpow(int b, int p, int mod) {
if (!p) return 1;
int ret = fpow(b, p / 2, mod);
if (p & 1) return ret * ret % mod * b % mod;
return ret * ret % mod;
}
int32_t main() {
boost();
cin >> n;
int suma = 0, sumb = 0;
for (int i = 0; i < n; i++) {
cin >> a[i].f >> a[i].s;
suma += a[i].f * (1ll << i);
sumb += a[i].s * (1ll << i);
}
int was = (1ll << n) - 1;
int d = suma - sumb;
//if (d % was != 0) return 0 * printf("No\n");
for (int t = 0; t < 32; t++) { //wtf???
for (int i = 0; i < n; i++) {
if (a[i].s < a[i].f) {
int d = (a[i].f - a[i].s + 1) / 2;
a[i].f -= d * 2;
a[(i + 1) % n].f += d;
}
}
}
int sum = 0;
for (int i = 0; i < MN * 2; i++) {
assert(a[i].f >= 0 && a[i].s >= 0);
if (a[i].f != a[i].s) return 0 * printf("No\n");
sum += fpow(2, i, was) * (a[i].f - a[i].s) % was;
}
if (sum % was == 0) printf("Yes\n");
else printf("No\n");
return 0;
}
Compilation message
remittance.cpp: In function 'int32_t main()':
remittance.cpp:34:9: warning: unused variable 'd' [-Wunused-variable]
34 | int d = suma - sumb;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
195 ms |
372 KB |
Output is correct |
3 |
Correct |
189 ms |
332 KB |
Output is correct |
4 |
Correct |
191 ms |
332 KB |
Output is correct |
5 |
Correct |
199 ms |
360 KB |
Output is correct |
6 |
Correct |
200 ms |
340 KB |
Output is correct |
7 |
Correct |
196 ms |
488 KB |
Output is correct |
8 |
Correct |
194 ms |
368 KB |
Output is correct |
9 |
Correct |
193 ms |
480 KB |
Output is correct |
10 |
Correct |
202 ms |
332 KB |
Output is correct |
11 |
Correct |
206 ms |
576 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
195 ms |
372 KB |
Output is correct |
3 |
Correct |
189 ms |
332 KB |
Output is correct |
4 |
Correct |
191 ms |
332 KB |
Output is correct |
5 |
Correct |
199 ms |
360 KB |
Output is correct |
6 |
Correct |
200 ms |
340 KB |
Output is correct |
7 |
Correct |
196 ms |
488 KB |
Output is correct |
8 |
Correct |
194 ms |
368 KB |
Output is correct |
9 |
Correct |
193 ms |
480 KB |
Output is correct |
10 |
Correct |
202 ms |
332 KB |
Output is correct |
11 |
Correct |
206 ms |
576 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
195 ms |
372 KB |
Output is correct |
3 |
Correct |
189 ms |
332 KB |
Output is correct |
4 |
Correct |
191 ms |
332 KB |
Output is correct |
5 |
Correct |
199 ms |
360 KB |
Output is correct |
6 |
Correct |
200 ms |
340 KB |
Output is correct |
7 |
Correct |
196 ms |
488 KB |
Output is correct |
8 |
Correct |
194 ms |
368 KB |
Output is correct |
9 |
Correct |
193 ms |
480 KB |
Output is correct |
10 |
Correct |
202 ms |
332 KB |
Output is correct |
11 |
Correct |
206 ms |
576 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
18 |
Halted |
0 ms |
0 KB |
- |