#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
constexpr int INF = 1e9+100;
int n;
void NO(){
printf("No\n");
exit(0);
}
int s[2002000];
void add(ll x, int p){
for (int i=0;i<60;i++) if (x&(1LL<<i)){
s[p+i]++;
}
for (int i=p;;i++){
if (s[i] > 1){
s[i+1] += s[i]/2;
s[i] %= 2;
}
else if (i-p > 60) break;
}
//for (int i=100;i>=0;i--) printf("%d", s[i]);
//printf("\n");
}
ll getq(vector<int> a, vector<int> b){
for (int i=0;i<n;i++){
ll x = (ll)a[i] - b[i] + INF;
add(x, i);
}
ll tmp = 0;
for (int j=0;j<40;j++){
//printf("%d -> %d\n", j+n, s[j+n]);
if (s[j+n]) tmp |= 1LL<<j;
}
//printf("%lld\n", tmp);
add(tmp+1, 0);
//printf("ok\n");
for (int i=0;i<n;i++) if (s[i]) return -1;
//printf("ok\n");
return tmp+1 - INF;
}
void naive(vector<int> a, vector<int> b){
ll q;
for (int i=0;i<n;i++){
if (!i){
ll aS = 0, bS = 0;
for (int j=0;j<n;j++){
aS += (ll)a[j] * (1LL<<j);
bS += (ll)b[j] * (1LL<<j);
}
if (aS!=0 && bS==0) NO();
if (aS < bS) NO();
if ((aS - bS) % ((1LL<<n)-1) != 0) NO();
q = (aS-bS) / ((1LL<<n)-1);
}
else q = (q+a[i-1]-b[i-1])/2;
if (q<0) NO();
//rotate(a.begin(), a.begin()+1, a.end());
//rotate(b.begin(), b.begin()+1, b.end());
}
printf("Yes\n");
exit(0);
}
int main(){
scanf("%d", &n);
vector<int> a, b;
int aa = 0, bb = 0;
for (int i=0;i<n;i++){
int x, y;
scanf("%d %d", &x, &y);
a.push_back(x);
b.push_back(y);
bb |= y;
aa |= x;
}
if (n<=40) naive(a, b);
if (aa && bb==0) NO();
ll q;
for (int i=0;i<n;i++){
if (!i){
q = getq(a, b);
if (q<0) NO();
}
else q = (q+a[i-1]-b[i-1])/2;
//printf("%lld\n", q);
if (q<0) NO();
//rotate(a.begin(), a.begin()+1, a.end());
//rotate(b.begin(), b.begin()+1, b.end());
}
printf("Yes\n");
return 0;
}
Compilation message
remittance.cpp: In function 'int main()':
remittance.cpp:82:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
82 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
remittance.cpp:87:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
87 | scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
220 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
220 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
232 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
0 ms |
212 KB |
Output is correct |
56 |
Correct |
0 ms |
212 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
220 KB |
Output is correct |
60 |
Correct |
1 ms |
220 KB |
Output is correct |
61 |
Correct |
0 ms |
220 KB |
Output is correct |
62 |
Correct |
1 ms |
220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
220 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
232 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
0 ms |
212 KB |
Output is correct |
56 |
Correct |
0 ms |
212 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
220 KB |
Output is correct |
60 |
Correct |
1 ms |
220 KB |
Output is correct |
61 |
Correct |
0 ms |
220 KB |
Output is correct |
62 |
Correct |
1 ms |
220 KB |
Output is correct |
63 |
Correct |
642 ms |
20084 KB |
Output is correct |
64 |
Correct |
317 ms |
20012 KB |
Output is correct |
65 |
Correct |
615 ms |
20084 KB |
Output is correct |
66 |
Correct |
309 ms |
20040 KB |
Output is correct |
67 |
Correct |
331 ms |
20088 KB |
Output is correct |
68 |
Correct |
328 ms |
19984 KB |
Output is correct |
69 |
Correct |
625 ms |
19984 KB |
Output is correct |
70 |
Correct |
287 ms |
19988 KB |
Output is correct |
71 |
Correct |
294 ms |
20132 KB |
Output is correct |
72 |
Correct |
327 ms |
20024 KB |
Output is correct |
73 |
Correct |
543 ms |
20048 KB |
Output is correct |
74 |
Correct |
276 ms |
20168 KB |
Output is correct |
75 |
Correct |
301 ms |
20036 KB |
Output is correct |
76 |
Correct |
382 ms |
20060 KB |
Output is correct |
77 |
Correct |
561 ms |
20128 KB |
Output is correct |
78 |
Correct |
171 ms |
8340 KB |
Output is correct |
79 |
Correct |
170 ms |
8348 KB |
Output is correct |
80 |
Correct |
526 ms |
20028 KB |
Output is correct |
81 |
Correct |
518 ms |
20116 KB |
Output is correct |
82 |
Correct |
146 ms |
8308 KB |
Output is correct |
83 |
Correct |
251 ms |
20052 KB |
Output is correct |
84 |
Correct |
265 ms |
20060 KB |
Output is correct |
85 |
Correct |
553 ms |
20448 KB |
Output is correct |
86 |
Correct |
542 ms |
20512 KB |
Output is correct |
87 |
Correct |
179 ms |
16276 KB |
Output is correct |
88 |
Correct |
305 ms |
28096 KB |
Output is correct |