# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
345175 | 2021-01-07T05:55:16 Z | daniel920712 | Rice Hub (IOI11_ricehub) | C++14 | 1000 ms | 892 KB |
#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++; } else break; } 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 364 KB | Output is correct |
2 | Execution timed out | 1086 ms | 364 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 0 ms | 364 KB | Output is correct |
3 | Correct | 0 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Execution timed out | 1077 ms | 364 KB | Time limit exceeded |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1089 ms | 364 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1078 ms | 892 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |