#include <iostream>
#include <algorithm>
using namespace std;
long long e[1005005],i,ok1,ok2,a[1005005],b[1005005],n,d[1005005],pp[1001],f[1000005],p,ppp[1001],poz1,poz2,poz3;
void make()
{
long long t=0,i;
for (i=1;(i<=e[0]||t)&&i<=1005002;++i)
{
e[i]+=t;
t=0;
if (e[i]>=0) {t=e[i]/2; e[i]%=2;}
else {t=(e[i]-1)/2; e[i]=(e[i]%2+2)%2;}
}
e[0]=i-1;
if (i>1005000) e[0]=1,e[1]=-1;
else while (e[e[0]]==0&&e[0]!=0) e[0]--;
}
int main()
{
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
ppp[0]=1;
for (i=1;i<=50;++i)
ppp[i]=2*ppp[i-1];
cin>>n;
for (i=1;i<=n;++i)
{
cin>>a[i];
if (a[i]!=0) ok1=1;
cin>>b[i];
if (b[i]!=0) ok2=1;
d[i]=a[i]-b[i];
e[i]=d[i];
}
e[0]=n;
if (!ok1&&!ok2) {cout<<"Yes"; return 0;}
else if (!ok2) {cout<<"No"; return 0;}
make();
if (n<=1000){
while (true)
{
if (e[0]==0) { break;}
if (e[e[0]]<0) {cout<<"No"; return 0;}
if (e[1]==0) {pp[++pp[0]]=0; for (i=1;i<e[0];++i) e[i]=e[i+1]; e[e[0]]=0; e[0]--;}
else
{
pp[++pp[0]]=1;
for (i=1;i<=n;++i)
e[i]--;
e[0]=max(e[0],n);
make();
}
}
reverse(pp+1,pp+pp[0]+1);
for (i=1;i<=pp[0];++i)
{
if (pp[i]==0) p*=2;
else p++;
}}
else
{
if (e[e[0]]<0) {cout<<"No"; return 0;}
if (e[0]==0) {p=0;}
else{
for (i=1;i<=100;++i)
if (e[i]==0) poz1=i;
if (poz1==0) {for (i=1;i<=e[0];++i) {if (e[i]==0) {cout<<"No"; return 0; }} if (e[0]==n) p=1;}
else{poz2=e[0]-poz1+1;
for (i=poz1+1;i<=poz2-1;++i)
{
if (e[i]==0) {cout<<"No"; return 0;}
}
for (i=1;i<=poz1;++i)
{
if (e[i]==e[poz2+i-1]) {cout<<"No"; return 0;}
}
for (i=1;i<=poz1;++i)
{
if (e[i]==1) {poz3=i; break;}
}
for (i=poz1;i>poz3;--i)
{
p*=2;
if (e[i]==0) p++;
}
for (i=poz3;i>=1;--i)
{
p*=2;
if (e[i]==1) p++;
}
if (n!=poz2-1) {cout<<"No"; return 0;}
}
}}
f[n]=p;
for (i=n;i>=2;--i)
{
f[i-1]=f[i]*2-d[i];
if (f[i-1]<0) {cout<<"No"; return 0;}
}
cout<<"Yes";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
8148 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
8148 KB |
Output is correct |
13 |
Correct |
7 ms |
8148 KB |
Output is correct |
14 |
Correct |
6 ms |
8148 KB |
Output is correct |
15 |
Correct |
7 ms |
8148 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
7 ms |
8148 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
7 ms |
8148 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
7 ms |
8108 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
7 ms |
8148 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
8148 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
8148 KB |
Output is correct |
13 |
Correct |
7 ms |
8148 KB |
Output is correct |
14 |
Correct |
6 ms |
8148 KB |
Output is correct |
15 |
Correct |
7 ms |
8148 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
7 ms |
8148 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
7 ms |
8148 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
7 ms |
8108 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
7 ms |
8148 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
7 ms |
8148 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
7 ms |
8164 KB |
Output is correct |
43 |
Correct |
7 ms |
8136 KB |
Output is correct |
44 |
Correct |
6 ms |
8148 KB |
Output is correct |
45 |
Correct |
6 ms |
8160 KB |
Output is correct |
46 |
Correct |
7 ms |
8148 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
6 ms |
8088 KB |
Output is correct |
49 |
Correct |
0 ms |
340 KB |
Output is correct |
50 |
Correct |
0 ms |
340 KB |
Output is correct |
51 |
Correct |
0 ms |
340 KB |
Output is correct |
52 |
Correct |
0 ms |
340 KB |
Output is correct |
53 |
Correct |
0 ms |
340 KB |
Output is correct |
54 |
Correct |
0 ms |
340 KB |
Output is correct |
55 |
Correct |
7 ms |
8148 KB |
Output is correct |
56 |
Correct |
0 ms |
340 KB |
Output is correct |
57 |
Correct |
6 ms |
8148 KB |
Output is correct |
58 |
Correct |
0 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
7 ms |
8148 KB |
Output is correct |
61 |
Correct |
1 ms |
340 KB |
Output is correct |
62 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
8148 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
8148 KB |
Output is correct |
13 |
Correct |
7 ms |
8148 KB |
Output is correct |
14 |
Correct |
6 ms |
8148 KB |
Output is correct |
15 |
Correct |
7 ms |
8148 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
7 ms |
8148 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
7 ms |
8148 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
7 ms |
8108 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
7 ms |
8148 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
7 ms |
8148 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
7 ms |
8164 KB |
Output is correct |
43 |
Correct |
7 ms |
8136 KB |
Output is correct |
44 |
Correct |
6 ms |
8148 KB |
Output is correct |
45 |
Correct |
6 ms |
8160 KB |
Output is correct |
46 |
Correct |
7 ms |
8148 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
6 ms |
8088 KB |
Output is correct |
49 |
Correct |
0 ms |
340 KB |
Output is correct |
50 |
Correct |
0 ms |
340 KB |
Output is correct |
51 |
Correct |
0 ms |
340 KB |
Output is correct |
52 |
Correct |
0 ms |
340 KB |
Output is correct |
53 |
Correct |
0 ms |
340 KB |
Output is correct |
54 |
Correct |
0 ms |
340 KB |
Output is correct |
55 |
Correct |
7 ms |
8148 KB |
Output is correct |
56 |
Correct |
0 ms |
340 KB |
Output is correct |
57 |
Correct |
6 ms |
8148 KB |
Output is correct |
58 |
Correct |
0 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
7 ms |
8148 KB |
Output is correct |
61 |
Correct |
1 ms |
340 KB |
Output is correct |
62 |
Correct |
0 ms |
340 KB |
Output is correct |
63 |
Correct |
193 ms |
31616 KB |
Output is correct |
64 |
Correct |
115 ms |
39364 KB |
Output is correct |
65 |
Correct |
193 ms |
39560 KB |
Output is correct |
66 |
Correct |
114 ms |
39480 KB |
Output is correct |
67 |
Correct |
128 ms |
39812 KB |
Output is correct |
68 |
Correct |
127 ms |
39792 KB |
Output is correct |
69 |
Correct |
193 ms |
39380 KB |
Output is correct |
70 |
Correct |
125 ms |
32004 KB |
Output is correct |
71 |
Correct |
117 ms |
32560 KB |
Output is correct |
72 |
Correct |
126 ms |
32596 KB |
Output is correct |
73 |
Correct |
192 ms |
31580 KB |
Output is correct |
74 |
Correct |
121 ms |
38064 KB |
Output is correct |
75 |
Correct |
114 ms |
32588 KB |
Output is correct |
76 |
Correct |
142 ms |
39012 KB |
Output is correct |
77 |
Correct |
195 ms |
39268 KB |
Output is correct |
78 |
Correct |
171 ms |
32660 KB |
Output is correct |
79 |
Correct |
142 ms |
32556 KB |
Output is correct |
80 |
Correct |
153 ms |
40428 KB |
Output is correct |
81 |
Correct |
145 ms |
32544 KB |
Output is correct |
82 |
Correct |
98 ms |
32628 KB |
Output is correct |
83 |
Correct |
100 ms |
32588 KB |
Output is correct |
84 |
Correct |
96 ms |
32600 KB |
Output is correct |
85 |
Correct |
216 ms |
39480 KB |
Output is correct |
86 |
Correct |
213 ms |
31668 KB |
Output is correct |
87 |
Correct |
165 ms |
32408 KB |
Output is correct |
88 |
Correct |
174 ms |
40288 KB |
Output is correct |