#include <bits/stdc++.h>
#define DIM 1000010
using namespace std;
long long a[DIM],b[DIM],x[DIM],p[22];
int n,i;
int verif(){
for (;;){
int ok2 = 0;
for (i=1;i<=n;i++){
/// trimit cat de mult pot
if (2 * x[i] <= a[i]){
if (x[i])
ok2 = 1;
a[i] -= 2 * x[i];
a[ (i < n) ? (i+1) : (1)] += x[i];
x[i] = 0;
} else {
long long val = a[i] / 2;
if (val)
ok2 = 1;
a[i] -= 2 * val;
a[(i < n) ? (i+1) : (1)] += val;
x[i] -= val;
}
}
if (!ok2)
break;
}
int ok = 1;
for (i=1;i<=n;i++)
if (x[i] != 0 || a[i] != b[i])
ok = 0;
return ok;
}
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n;
long long sum = 0, sum2 = 0;
for (i=1;i<=n;i++){
cin>>a[i]>>b[i];
sum += a[i];
sum2 += b[i];
}
if (!sum2){
if (!sum)
cout<<"Yes";
else cout<<"No";
return 0;
}
/// ce porcarie
for (;;){
int ok = 0;
for (i=1;i<=n;i++){
if (a[i] <= b[i])
continue;
long long val = (a[i] - b[i] + 1) / 2;
if (val)
ok = 1;
a[i] -= 2*val;
a[(i < n) ? (i+1) : (1)] += val;
}
if (!ok)
break;
}
int ok = 1;
for (i=1;i<=n;i++)
if (a[i] != b[i]){
ok = 0;
break;
}
if (ok)
cout<<"Yes";
else cout<<"No";
return 0;
if (n == 2){
long long val = a[1] - b[1] + 2 * (a[2] - b[2]);
if (val % 3){
cout<<"No";
return 0;
}
x[2] = val / 3;
if ( (a[1] - b[1] + x[2]) % 2){
cout<<"No";
return 0;
}
x[1] = (a[1] - b[1] + x[2]) / 2;
if (x[1] < 0 || x[2] < 0){
cout<<"No";
return 0;
}
if (verif())
cout<<"Yes";
else cout<<"No";
return 0;
}
p[0] = 1;
for (i=1;i<=20;i++)
p[i] = p[i-1] * 2;
long long val = p[n-1] * (a[1] - b[1]) + p[n-2] * (a[n] - b[n]);
for (i=n-1;i>=2;i--)
val += p[i-2] * (a[i] - b[i]);
if (val % (p[n]-1)){
cout<<"No";
return 0;
}
x[1] = val / (p[n]-1);
if (val < 0){
cout<<"No";
return 0;
}
for (i=2;i<=n;i++){
long long val = a[i] - b[i] + x[i-1];
if (val % 2 || val < 0){
cout<<"No";
return 0;
}
x[i] = val / 2;
}
for (i=1;i<=n;i++){
long long val = a[i] + x[ (i > 1) ? (i-1) : (n) ] - 2 * x[i];
if ( val != b[i] ){
cout<<"No";
return 0;
}
}
if (verif())
cout<<"Yes";
else cout<<"No";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
0 ms |
204 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Correct |
0 ms |
204 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
0 ms |
204 KB |
Output is correct |
44 |
Correct |
0 ms |
204 KB |
Output is correct |
45 |
Correct |
0 ms |
204 KB |
Output is correct |
46 |
Correct |
0 ms |
204 KB |
Output is correct |
47 |
Correct |
0 ms |
204 KB |
Output is correct |
48 |
Correct |
0 ms |
204 KB |
Output is correct |
49 |
Correct |
0 ms |
204 KB |
Output is correct |
50 |
Correct |
0 ms |
204 KB |
Output is correct |
51 |
Correct |
1 ms |
204 KB |
Output is correct |
52 |
Correct |
0 ms |
204 KB |
Output is correct |
53 |
Correct |
0 ms |
204 KB |
Output is correct |
54 |
Correct |
0 ms |
204 KB |
Output is correct |
55 |
Correct |
1 ms |
204 KB |
Output is correct |
56 |
Correct |
0 ms |
204 KB |
Output is correct |
57 |
Correct |
0 ms |
204 KB |
Output is correct |
58 |
Correct |
1 ms |
204 KB |
Output is correct |
59 |
Correct |
0 ms |
204 KB |
Output is correct |
60 |
Correct |
0 ms |
204 KB |
Output is correct |
61 |
Correct |
0 ms |
204 KB |
Output is correct |
62 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
0 ms |
204 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Correct |
0 ms |
204 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
0 ms |
204 KB |
Output is correct |
44 |
Correct |
0 ms |
204 KB |
Output is correct |
45 |
Correct |
0 ms |
204 KB |
Output is correct |
46 |
Correct |
0 ms |
204 KB |
Output is correct |
47 |
Correct |
0 ms |
204 KB |
Output is correct |
48 |
Correct |
0 ms |
204 KB |
Output is correct |
49 |
Correct |
0 ms |
204 KB |
Output is correct |
50 |
Correct |
0 ms |
204 KB |
Output is correct |
51 |
Correct |
1 ms |
204 KB |
Output is correct |
52 |
Correct |
0 ms |
204 KB |
Output is correct |
53 |
Correct |
0 ms |
204 KB |
Output is correct |
54 |
Correct |
0 ms |
204 KB |
Output is correct |
55 |
Correct |
1 ms |
204 KB |
Output is correct |
56 |
Correct |
0 ms |
204 KB |
Output is correct |
57 |
Correct |
0 ms |
204 KB |
Output is correct |
58 |
Correct |
1 ms |
204 KB |
Output is correct |
59 |
Correct |
0 ms |
204 KB |
Output is correct |
60 |
Correct |
0 ms |
204 KB |
Output is correct |
61 |
Correct |
0 ms |
204 KB |
Output is correct |
62 |
Correct |
0 ms |
204 KB |
Output is correct |
63 |
Correct |
825 ms |
33152 KB |
Output is correct |
64 |
Correct |
317 ms |
19808 KB |
Output is correct |
65 |
Correct |
821 ms |
34888 KB |
Output is correct |
66 |
Correct |
305 ms |
19748 KB |
Output is correct |
67 |
Correct |
346 ms |
21284 KB |
Output is correct |
68 |
Correct |
456 ms |
23672 KB |
Output is correct |
69 |
Correct |
832 ms |
35320 KB |
Output is correct |
70 |
Correct |
321 ms |
19804 KB |
Output is correct |
71 |
Correct |
365 ms |
21164 KB |
Output is correct |
72 |
Correct |
449 ms |
23640 KB |
Output is correct |
73 |
Correct |
839 ms |
35268 KB |
Output is correct |
74 |
Correct |
303 ms |
19852 KB |
Output is correct |
75 |
Correct |
347 ms |
21200 KB |
Output is correct |
76 |
Correct |
485 ms |
23616 KB |
Output is correct |
77 |
Correct |
800 ms |
35408 KB |
Output is correct |
78 |
Correct |
569 ms |
27572 KB |
Output is correct |
79 |
Correct |
570 ms |
27524 KB |
Output is correct |
80 |
Correct |
575 ms |
27536 KB |
Output is correct |
81 |
Correct |
618 ms |
27672 KB |
Output is correct |
82 |
Correct |
347 ms |
19916 KB |
Output is correct |
83 |
Correct |
358 ms |
20020 KB |
Output is correct |
84 |
Correct |
285 ms |
19736 KB |
Output is correct |
85 |
Correct |
896 ms |
36396 KB |
Output is correct |
86 |
Correct |
863 ms |
36412 KB |
Output is correct |
87 |
Correct |
626 ms |
28652 KB |
Output is correct |
88 |
Correct |
612 ms |
28580 KB |
Output is correct |