Submission #964853

#TimeUsernameProblemLanguageResultExecution timeMemory
964853anango쌀 창고 (IOI11_ricehub)C++17
100 / 100
12 ms5328 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...