#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("ok.in");
ofstream cout("ok.out");
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |