#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
#define rep(i,a,b) for(int i=a;i<b;i++)
int number[2000000];
void add(int pos, lld x){
if(x==0)return;
if(x>0){
number[pos]+=x%2;
x/=2;
if(number[pos]==2){
number[pos]=0;
x++;
}
add(pos+1,x);
}else{
number[pos]+=x%2;
x/=2;
if(number[pos]==-2){
number[pos]=0;
x--;
}
add(pos+1,x);
}
}
int main(){
int n;
scanf("%d",&n);
lld a[n];
lld b[n];
rep(i,0,n){
scanf("%lld %lld",&a[i],&b[i]);
}
bool eq=true;
rep(i,0,n){
if(a[i]!=b[i])eq=false;
}
if(eq){
printf("Yes\n");
return 0;
}
/*eq=true;
rep(i,0,n){
if(0!=b[i])eq=false;
}
if(eq){
printf("No\n");
return 0;
}*/
rep(i,0,2000000)number[i]=0;
rep(i,0,n){
add(i,a[i]-b[i]);
}
int last=-1;
for(int i=1999999;i>-1;i--){
if(number[i]==1)last=i;
if(number[i]==-1){
if(last==-1){
printf("No\n");
return 0;
}else{
rep(j,i,last){
number[j]=1;
}
number[last]=0;
last=i;
}
}
}
/*rep(i,0,10){
cout<<number[i];
}cout<<endl;*/
lld Pow[60];
Pow[0]=1;
rep(i,1,59)Pow[i]=Pow[i-1]*2;
lld c[n];
c[n-1]=0;
for(int i=1999999;i>=n;i--){
while(number[i]==1){
int m=i-n;
number[m]++;
number[i]--;
c[n-1]+=Pow[i-n];
while(number[m]==2){
number[m]=0;
number[m+1]++;
m++;
}
}
}
//rep(i,0,10)cout<<number[i]<<endl;
//cout<<c[n-1]<<endl;
int num=number[0];
rep(i,0,n){
if(number[i]!=num){
printf("No\n");
return 0;
}
}
c[n-1]+=num;
//cout<<c[n-1]<<endl;
for(int i=n-2;i>-1;i--){
c[i]=c[i+1]*2+b[i+1]-a[i+1];
}
rep(i,0,n){
if(c[i]<0){
printf("No\n");
return 0;
}
}
rep(turn,0,60){
rep(i,0,n){
lld C=min(c[i],a[i]/2);
c[i]-=C;
a[i]-=2*C;
a[(i+1)%n]+=C;
}
}
rep(i,0,n){
if(a[i]!=b[i]){
printf("No\n");
return 0;
}
}
printf("Yes\n");
return 0;
}
Compilation message
remittance.cpp: In function 'int main()':
remittance.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
remittance.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld",&a[i],&b[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
8184 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
14 ms |
8056 KB |
Output is correct |
5 |
Correct |
12 ms |
8184 KB |
Output is correct |
6 |
Correct |
14 ms |
8184 KB |
Output is correct |
7 |
Correct |
12 ms |
8184 KB |
Output is correct |
8 |
Correct |
14 ms |
8184 KB |
Output is correct |
9 |
Correct |
12 ms |
8184 KB |
Output is correct |
10 |
Correct |
12 ms |
8184 KB |
Output is correct |
11 |
Correct |
12 ms |
8312 KB |
Output is correct |
12 |
Correct |
12 ms |
8184 KB |
Output is correct |
13 |
Correct |
12 ms |
8128 KB |
Output is correct |
14 |
Correct |
10 ms |
8184 KB |
Output is correct |
15 |
Correct |
12 ms |
8184 KB |
Output is correct |
16 |
Correct |
12 ms |
8184 KB |
Output is correct |
17 |
Correct |
10 ms |
8184 KB |
Output is correct |
18 |
Correct |
12 ms |
8188 KB |
Output is correct |
19 |
Correct |
12 ms |
8156 KB |
Output is correct |
20 |
Correct |
12 ms |
8208 KB |
Output is correct |
21 |
Correct |
12 ms |
8184 KB |
Output is correct |
22 |
Correct |
12 ms |
8184 KB |
Output is correct |
23 |
Correct |
12 ms |
8184 KB |
Output is correct |
24 |
Correct |
12 ms |
8184 KB |
Output is correct |
25 |
Correct |
13 ms |
8184 KB |
Output is correct |
26 |
Correct |
12 ms |
8184 KB |
Output is correct |
27 |
Correct |
10 ms |
8184 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
12 ms |
8184 KB |
Output is correct |
30 |
Correct |
12 ms |
8184 KB |
Output is correct |
31 |
Correct |
12 ms |
8184 KB |
Output is correct |
32 |
Correct |
12 ms |
8156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
8184 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
14 ms |
8056 KB |
Output is correct |
5 |
Correct |
12 ms |
8184 KB |
Output is correct |
6 |
Correct |
14 ms |
8184 KB |
Output is correct |
7 |
Correct |
12 ms |
8184 KB |
Output is correct |
8 |
Correct |
14 ms |
8184 KB |
Output is correct |
9 |
Correct |
12 ms |
8184 KB |
Output is correct |
10 |
Correct |
12 ms |
8184 KB |
Output is correct |
11 |
Correct |
12 ms |
8312 KB |
Output is correct |
12 |
Correct |
12 ms |
8184 KB |
Output is correct |
13 |
Correct |
12 ms |
8128 KB |
Output is correct |
14 |
Correct |
10 ms |
8184 KB |
Output is correct |
15 |
Correct |
12 ms |
8184 KB |
Output is correct |
16 |
Correct |
12 ms |
8184 KB |
Output is correct |
17 |
Correct |
10 ms |
8184 KB |
Output is correct |
18 |
Correct |
12 ms |
8188 KB |
Output is correct |
19 |
Correct |
12 ms |
8156 KB |
Output is correct |
20 |
Correct |
12 ms |
8208 KB |
Output is correct |
21 |
Correct |
12 ms |
8184 KB |
Output is correct |
22 |
Correct |
12 ms |
8184 KB |
Output is correct |
23 |
Correct |
12 ms |
8184 KB |
Output is correct |
24 |
Correct |
12 ms |
8184 KB |
Output is correct |
25 |
Correct |
13 ms |
8184 KB |
Output is correct |
26 |
Correct |
12 ms |
8184 KB |
Output is correct |
27 |
Correct |
10 ms |
8184 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
12 ms |
8184 KB |
Output is correct |
30 |
Correct |
12 ms |
8184 KB |
Output is correct |
31 |
Correct |
12 ms |
8184 KB |
Output is correct |
32 |
Correct |
12 ms |
8156 KB |
Output is correct |
33 |
Correct |
10 ms |
8184 KB |
Output is correct |
34 |
Correct |
12 ms |
8184 KB |
Output is correct |
35 |
Correct |
12 ms |
8100 KB |
Output is correct |
36 |
Correct |
13 ms |
8104 KB |
Output is correct |
37 |
Correct |
12 ms |
8184 KB |
Output is correct |
38 |
Correct |
14 ms |
8056 KB |
Output is correct |
39 |
Correct |
14 ms |
8060 KB |
Output is correct |
40 |
Correct |
12 ms |
8184 KB |
Output is correct |
41 |
Correct |
12 ms |
8184 KB |
Output is correct |
42 |
Correct |
12 ms |
8184 KB |
Output is correct |
43 |
Correct |
12 ms |
8184 KB |
Output is correct |
44 |
Correct |
12 ms |
8184 KB |
Output is correct |
45 |
Correct |
12 ms |
8188 KB |
Output is correct |
46 |
Correct |
10 ms |
8184 KB |
Output is correct |
47 |
Correct |
12 ms |
8184 KB |
Output is correct |
48 |
Correct |
10 ms |
8184 KB |
Output is correct |
49 |
Correct |
12 ms |
8188 KB |
Output is correct |
50 |
Correct |
12 ms |
8184 KB |
Output is correct |
51 |
Correct |
14 ms |
8184 KB |
Output is correct |
52 |
Correct |
14 ms |
8184 KB |
Output is correct |
53 |
Correct |
12 ms |
8184 KB |
Output is correct |
54 |
Correct |
12 ms |
8184 KB |
Output is correct |
55 |
Correct |
12 ms |
8184 KB |
Output is correct |
56 |
Correct |
12 ms |
8184 KB |
Output is correct |
57 |
Correct |
10 ms |
8184 KB |
Output is correct |
58 |
Correct |
2 ms |
256 KB |
Output is correct |
59 |
Correct |
12 ms |
8184 KB |
Output is correct |
60 |
Correct |
14 ms |
8184 KB |
Output is correct |
61 |
Correct |
13 ms |
8184 KB |
Output is correct |
62 |
Correct |
12 ms |
8184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
8184 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
14 ms |
8056 KB |
Output is correct |
5 |
Correct |
12 ms |
8184 KB |
Output is correct |
6 |
Correct |
14 ms |
8184 KB |
Output is correct |
7 |
Correct |
12 ms |
8184 KB |
Output is correct |
8 |
Correct |
14 ms |
8184 KB |
Output is correct |
9 |
Correct |
12 ms |
8184 KB |
Output is correct |
10 |
Correct |
12 ms |
8184 KB |
Output is correct |
11 |
Correct |
12 ms |
8312 KB |
Output is correct |
12 |
Correct |
12 ms |
8184 KB |
Output is correct |
13 |
Correct |
12 ms |
8128 KB |
Output is correct |
14 |
Correct |
10 ms |
8184 KB |
Output is correct |
15 |
Correct |
12 ms |
8184 KB |
Output is correct |
16 |
Correct |
12 ms |
8184 KB |
Output is correct |
17 |
Correct |
10 ms |
8184 KB |
Output is correct |
18 |
Correct |
12 ms |
8188 KB |
Output is correct |
19 |
Correct |
12 ms |
8156 KB |
Output is correct |
20 |
Correct |
12 ms |
8208 KB |
Output is correct |
21 |
Correct |
12 ms |
8184 KB |
Output is correct |
22 |
Correct |
12 ms |
8184 KB |
Output is correct |
23 |
Correct |
12 ms |
8184 KB |
Output is correct |
24 |
Correct |
12 ms |
8184 KB |
Output is correct |
25 |
Correct |
13 ms |
8184 KB |
Output is correct |
26 |
Correct |
12 ms |
8184 KB |
Output is correct |
27 |
Correct |
10 ms |
8184 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
12 ms |
8184 KB |
Output is correct |
30 |
Correct |
12 ms |
8184 KB |
Output is correct |
31 |
Correct |
12 ms |
8184 KB |
Output is correct |
32 |
Correct |
12 ms |
8156 KB |
Output is correct |
33 |
Correct |
10 ms |
8184 KB |
Output is correct |
34 |
Correct |
12 ms |
8184 KB |
Output is correct |
35 |
Correct |
12 ms |
8100 KB |
Output is correct |
36 |
Correct |
13 ms |
8104 KB |
Output is correct |
37 |
Correct |
12 ms |
8184 KB |
Output is correct |
38 |
Correct |
14 ms |
8056 KB |
Output is correct |
39 |
Correct |
14 ms |
8060 KB |
Output is correct |
40 |
Correct |
12 ms |
8184 KB |
Output is correct |
41 |
Correct |
12 ms |
8184 KB |
Output is correct |
42 |
Correct |
12 ms |
8184 KB |
Output is correct |
43 |
Correct |
12 ms |
8184 KB |
Output is correct |
44 |
Correct |
12 ms |
8184 KB |
Output is correct |
45 |
Correct |
12 ms |
8188 KB |
Output is correct |
46 |
Correct |
10 ms |
8184 KB |
Output is correct |
47 |
Correct |
12 ms |
8184 KB |
Output is correct |
48 |
Correct |
10 ms |
8184 KB |
Output is correct |
49 |
Correct |
12 ms |
8188 KB |
Output is correct |
50 |
Correct |
12 ms |
8184 KB |
Output is correct |
51 |
Correct |
14 ms |
8184 KB |
Output is correct |
52 |
Correct |
14 ms |
8184 KB |
Output is correct |
53 |
Correct |
12 ms |
8184 KB |
Output is correct |
54 |
Correct |
12 ms |
8184 KB |
Output is correct |
55 |
Correct |
12 ms |
8184 KB |
Output is correct |
56 |
Correct |
12 ms |
8184 KB |
Output is correct |
57 |
Correct |
10 ms |
8184 KB |
Output is correct |
58 |
Correct |
2 ms |
256 KB |
Output is correct |
59 |
Correct |
12 ms |
8184 KB |
Output is correct |
60 |
Correct |
14 ms |
8184 KB |
Output is correct |
61 |
Correct |
13 ms |
8184 KB |
Output is correct |
62 |
Correct |
12 ms |
8184 KB |
Output is correct |
63 |
Correct |
447 ms |
23792 KB |
Output is correct |
64 |
Correct |
583 ms |
31612 KB |
Output is correct |
65 |
Correct |
862 ms |
31736 KB |
Output is correct |
66 |
Correct |
581 ms |
31696 KB |
Output is correct |
67 |
Correct |
614 ms |
31736 KB |
Output is correct |
68 |
Correct |
657 ms |
31684 KB |
Output is correct |
69 |
Correct |
857 ms |
31784 KB |
Output is correct |
70 |
Correct |
185 ms |
23964 KB |
Output is correct |
71 |
Correct |
215 ms |
23816 KB |
Output is correct |
72 |
Correct |
258 ms |
23888 KB |
Output is correct |
73 |
Correct |
476 ms |
24060 KB |
Output is correct |
74 |
Correct |
204 ms |
31608 KB |
Output is correct |
75 |
Correct |
226 ms |
31608 KB |
Output is correct |
76 |
Correct |
273 ms |
31668 KB |
Output is correct |
77 |
Correct |
458 ms |
31608 KB |
Output is correct |
78 |
Correct |
790 ms |
31832 KB |
Output is correct |
79 |
Correct |
401 ms |
24048 KB |
Output is correct |
80 |
Correct |
786 ms |
31692 KB |
Output is correct |
81 |
Correct |
393 ms |
23808 KB |
Output is correct |
82 |
Correct |
570 ms |
31660 KB |
Output is correct |
83 |
Correct |
171 ms |
23852 KB |
Output is correct |
84 |
Correct |
152 ms |
15992 KB |
Output is correct |
85 |
Correct |
840 ms |
31672 KB |
Output is correct |
86 |
Correct |
434 ms |
23924 KB |
Output is correct |
87 |
Correct |
671 ms |
31684 KB |
Output is correct |
88 |
Correct |
675 ms |
31664 KB |
Output is correct |