# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
302435 | UserIsUndefined | Rice Hub (IOI11_ricehub) | C++14 | 1039 ms | 896 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 <bits/stdc++.h>
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
int low = 0;
int high = R*2;
while(low < high){
int mid = (high+low)/2;
long long sum = 0;
long long now = mid/2;
long long pluss = mid - mid/2 - 1;
long long mines = mid - (pluss + 1);
int good = false;
for (int i = now ; i + pluss < R ; i++){
long long sum = 0;
for (int j = i - mines ; j <= i + pluss ; j++){
sum+= llabs(X[j] - X[i]);
}
if (sum <= B){
low = mid + 1;
good = true;
break;
}
}
if (good)continue;
high = mid - 1;
}
int best = low - 1;
for (int i = max(best - 5 , 0) ; i <= min(R , best + 5) ; i++){
long long pluss = i - i/2 - 1;
long long mines = i - (pluss + 1);
int good = false;
for (int j = i/2 ; j + pluss < R ; j++){
long long sum = 0;
for (int f = j - mines ; f <= j + pluss ; f++){
sum+= llabs(X[f] - X[j]);
}
if (sum <= B){
best = i;
good = true;
break;
}
}
}
return best;
}
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... |