# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
964848 |
2024-04-17T16:25:30 Z |
anango |
Rice Hub (IOI11_ricehub) |
C++17 |
|
12 ms |
5420 KB |
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
int INF=1000000000000000007;
int cost;
vector<int> rice;
vector<int> pref = {0};
bool test(int n) {
//returns true if it's possible to solve with n fields, else false
int mincost=INF;
int len=rice.size();
int fl=(n-1)/2;
int ce=(n)/2;
for (int spos=fl; spos+ce<len; spos++) {
//put at rice[spos]
int cost1 = fl*rice[spos] - (pref[spos] - pref[spos-fl]);
int cost2 = (pref[spos+ce+1] - pref[spos+1]) - ce*rice[spos];
int totcost = cost1+cost2;
mincost=min(mincost,totcost);
//cout << n <<" " << spos <<" " << cost1 << " " <<cost2 <<" " << totcost << endl;
}
return mincost<=cost;
}
int32_t besthub(int32_t R, int32_t L, int32_t X[], long long B) {
cost=B;
for (int i=0; i<R; i++) {
rice.push_back(X[i]);
pref.push_back(pref.back()+X[i]);
}
int lef=1;
int ri=R;
while (lef<ri) {
int m=(lef+ri)/2;
if (test(m)) {
lef=m+1;
ri=ri;
}
else {
lef=lef;
ri=m;
}
}
return lef-1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
448 KB |
Output is correct |
4 |
Correct |
0 ms |
448 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1112 KB |
Output is correct |
2 |
Correct |
3 ms |
1116 KB |
Output is correct |
3 |
Incorrect |
12 ms |
5420 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |