# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
345173 | daniel920712 | Rice Hub (IOI11_ricehub) | C++14 | 42 ms | 3168 KiB |
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 "ricehub.h"
#include <algorithm>
#include <vector>
using namespace std;
vector < long long > all;
vector < long long > a,b;
int besthub(int R, int L, int X[], long long B)
{
long long now=0,i,j,ans=0,t=0,x,y=0;
for(i=0;i<R;i++)
{
a.push_back(X[i]-X[0]);
if(i) a[i]+=a[i-1];
}
for(i=0;i<R;i++)
{
b.push_back(X[R-1]-X[i]);
if(i) b[i]+=b[i-1];
}
ans=max(upper_bound(a.begin(),a.end(),B)-a.begin(),upper_bound(b.begin(),b.end(),B)-b.begin());
a.clear();
b.clear();
now=0;
for(i=0;i<R;i++)
{
if(now+(X[i]-X[0])>B)
{
t=i;
x=i;
break;
}
now+=X[i]-X[0];
}
//printf("0 %lld %lld %lld %lld\n",x,y,t,now);
y=0;
ans=max(ans,t);
for(i=1;i<R;i++)
{
now+=(X[i]-X[i-1])*(y+1);
now-=(X[i]-X[i-1])*(x-1);
y++;
x--;
if(x==0)
{
x++;
t++;
}
/*while(1)
{
if(x==1||y==0) break;
if(i-y-1>=0&&X[i+x-1]-X[i]>=X[i]-X[i-y-1])
{
now-=X[i+x-1]-X[i];
now+=X[i]-X[i-y-1];
x--;
y++;
}
else if(i+x<R&&X[i+x]-X[i]<=X[i]-X[i-y])
{
now+=X[i+x]-X[i];
now-=X[i]-X[i-y];
y--;
x++;
}
}*/
while(now>B)
{
if(y==0)
{
now-=X[i+x-1]-X[i];
x--;
t--;
}
else if(X[i+x-1]-X[i]<=X[i]-X[i-y])
{
now-=X[i]-X[i-y];
y--;
t--;
}
else
{
now-=X[i+x-1]-X[i];
x--;
t--;
}
}
while(now<=B)
{
if(i+x>=R&&i-y-1>=0)
{
if(now+X[i]-X[i-y-1]<=B)
{
y++;
t++;
now+=X[i]-X[i-y-1];
}
else break;
}
else if(i+x<R&&i-y-1<0)
{
if(now+X[i+x]-X[i]<=B)
{
x++;
t++;
now+=X[i+x]-X[i];
}
else break;
}
else if(i+x<R&&i-y-1>=0)
{
if(X[i+x]-X[i]<=X[i]-X[i-y-1])
{
if(now+X[i+x]-X[i]<=B)
{
x++;
t++;
now+=X[i+x]-X[i];
}
else break;
}
else
{
if(now+X[i]-X[i-y-1]<=B)
{
y++;
t++;
now+=X[i]-X[i-y-1];
}
else break;
}
}
else break;
}
ans=max(ans,t);
}
return (int) ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |