# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
964853 |
2024-04-17T16:29:07 Z |
anango |
Rice Hub (IOI11_ricehub) |
C++17 |
|
12 ms |
5328 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;
}
}
if (!test(lef)) {
lef--;
}
return lef;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
444 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
600 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
548 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
756 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
452 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
476 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
488 KB |
Output is correct |
24 |
Correct |
1 ms |
456 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
984 KB |
Output is correct |
2 |
Correct |
2 ms |
984 KB |
Output is correct |
3 |
Correct |
11 ms |
4300 KB |
Output is correct |
4 |
Correct |
11 ms |
5324 KB |
Output is correct |
5 |
Correct |
6 ms |
4016 KB |
Output is correct |
6 |
Correct |
7 ms |
3800 KB |
Output is correct |
7 |
Correct |
9 ms |
5072 KB |
Output is correct |
8 |
Correct |
9 ms |
5324 KB |
Output is correct |
9 |
Correct |
7 ms |
3796 KB |
Output is correct |
10 |
Correct |
7 ms |
3800 KB |
Output is correct |
11 |
Correct |
12 ms |
5328 KB |
Output is correct |
12 |
Correct |
10 ms |
5328 KB |
Output is correct |
13 |
Correct |
7 ms |
4208 KB |
Output is correct |
14 |
Correct |
6 ms |
4012 KB |
Output is correct |
15 |
Correct |
8 ms |
5088 KB |
Output is correct |
16 |
Correct |
8 ms |
5072 KB |
Output is correct |
17 |
Correct |
10 ms |
5328 KB |
Output is correct |
18 |
Correct |
9 ms |
5328 KB |
Output is correct |
19 |
Correct |
10 ms |
5328 KB |
Output is correct |
20 |
Correct |
10 ms |
5328 KB |
Output is correct |