# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
288124 | SomeoneUnknown | Bigger segments (IZhO19_segments) | C++14 | 149 ms | 13816 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 <bits/stdc++.h>
using namespace std;
int main(){
int n;
scanf("%d", &n);
long long pfs[n+1];
int segs[n+1];
long long hval[n+1];
segs[0] = 0;
hval[0] = 1;
for(int i = 1; i <= n; ++i){
scanf("%lld", &pfs[i]);
pfs[i] += pfs[i-1];
segs[i] = 0;
hval[i] = (long long)n*1000000009;
}
for(int i = 0; i < n; ++i){
segs[i+1] = max(segs[i], segs[i+1]);
hval[i+1] = min(pfs[i+1]-pfs[i]+hval[i], hval[i+1]);
int lo = 0;
int hi = n+1;
while(hi-lo>1){
int mid = (hi+lo)/2;
if(pfs[mid] >= pfs[i] + hval[i]){
hi = mid;
}else{
lo = mid;
}
}
if(hi <= n){
segs[hi] = segs[i]+1;
hval[hi] = min(pfs[hi]-pfs[i], hval[hi]);
//printf("Updating %d to %d ", hi, hval[hi]);
}
//printf("%d %d\n", segs[i], hval[i]);
}
printf("%d", segs[n]);
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |