# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
302429 | UserIsUndefined | Rice Hub (IOI11_ricehub) | C++14 | 246 ms | 1852 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;
// cout << mid << " " << low << " " << high << endl;
long long sum = 0;
long long now = mid/2;
long long pluss = mid - mid/2 - 1;
long long mines = mid - (pluss + 1);
// cout << "lenth " << mid << endl;
// cout << now << " << now " << pluss << " << pluse " << mines << " << mines " << endl;
// for (int i = 0 ; i < mid ; i++){
// sum+= llabs(X[now] - X[i]);
// }
// cout << "first sum " << sum << endl;
// cout << "B" << B << endl;
// if (sum <= B){
//
// low = mid + 1;
// continue;
// }
int good = false;
// cout << "len = " << mid << endl;
// cout << "sums are : " << endl;
for (int i = now ; i + pluss < R ; i++){
long long sum = 0;
// cout << "middation " << i << endl;
// cout << "from " << i - mines << " to " << i + pluss << endl;
for (int j = i - mines ; j <= i + pluss ; j++){
sum+= llabs(X[j] - X[i]);
}
// cout << sum << endl;
// int bye = X[i - mines - 1];
//// cout << "bye " << bye << endl;
// sum-= llabs(X[i-1] - bye);
//// cout << "sum without bye " << sum << endl;
// int hello = X[i + pluss];
//// cout << "hello " << hello << endl;
// sum+= llabs(X[i] - hello);
//// cout << "sum with hello " << sum << endl;
//
// sum+= llabs(X[i] - X[i-1])*(mines - 1);
//
//// cout << "sum with pre" << sum << endl;
//
// sum-= llabs(X[i] - X[i-1])*(pluss - 1);
//
//// cout << "sum without after" << sum << endl;
// cout << "new sum " << sum << endl;
if (sum <= B){
low = mid + 1;
good = true;
break;
}
}
// cout << "\n\n\n";
if (good)continue;
high = mid - 1;
}
int best = low - 1;
// for (int i = max(low - 5, 0) ; i <= min(low + 5, R) ; i++){
// long long sum = 0;
//
// long long now = X[i/2];
//
// long long pluss = i - i/2 - 1;
//
// long long mines = i - pluss + 1;
//
// cout << "for " << i << endl;
//
// cout << "sums are :\n";
//
//
// for (int j = 0 ; j < i ; j++){
// sum+= llabs(now - X[j]);
// }
//
// cout << sum << endl;
//
// if (sum <= B){
// best = i;
// continue;
// }
//
// int good = false;
//
//
// for (int j = now + 1 ; j + pluss - 1 < R ; j++){
// int bye = X[j - mines];
// sum-= llabs(X[j-1] - bye);
// int hello = X[j + pluss];
// sum+= llabs(X[j] - hello);
//
// sum+= llabs(X[j] - X[j-1])*mines;
//
// sum-= llabs(X[j] - X[j-1])*(pluss - 1);
//
// cout << sum << endl;
//
// if (sum <= B){
// best = i;
// good = true;
// break;
// }
//
// }
//
// if (good)continue;
// }
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... |