This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "prize.h"
using namespace std;
int i,j,nn,m,l,r,c,xl,xr,maz,rez,mas[200005][2];
vector<int> xx;
vector<int> aask(int h)
{
if (mas[h][0]==-1&&mas[h][1]==-1)
{
xx=ask(nn-1-h);
mas[h][0]=xx[1];
mas[h][1]=xx[0];
}
xx[0]=mas[h][0];
xx[1]=mas[h][1];
return xx;
}
int find_best(int n)
{
nn=n;
i=0;
while (i<n-1)
{
mas[i][0]=-1;
mas[i][1]=-1;
i++;
}
l=0;
r=n-1;
rez=0;
maz=0;
while (true)
{
while (l<r)
{
c=l+(r-l)/2;
xx=aask(c);
xl=xx[0];
xr=xx[1];
if (xl+xr==0)
{
return n-1-c;
}
if (xl+xr>maz)
{
l=0;
r=n-1;
rez=0;
maz=xl+xr;
}
else if (xl+xr<maz)
{
r=c;
}
else if (xl>rez)
{
r=c-1;
}
else
{
l=c+1;
}
}
if (l<=n-1)
{
xx=aask(l);
xl=xx[0];
xr=xx[1];
}
if (xl+xr==0)
{
return n-1-l;
}
rez++;
l++;
if (l<=n-1)
{
xx=(aask(l));
xl=xx[0];
xr=xx[1];
if (xl+xr==0)
{
return n-1-l;
}
}
while (xl+xr<maz&&l<n-1)
{
l++;
rez++;
xx=(aask(l));
xl=xx[0];
xr=xx[1];
if (xl+xr==0)
{
return n-1-l;
}
}
if (xl+xr>maz)
{
maz=xl+xr;
l=0;
r=n-1;
rez=0;
}
r=n-1;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |