Submission #104887

#TimeUsernameProblemLanguageResultExecution timeMemory
104887popovicirobertRice Hub (IOI11_ricehub)C++14
42 / 100
270 ms3004 KiB
#include "ricehub.h" #include <bits/stdc++.h> #define ll long long using namespace std; vector <ll> sp; vector <int> x; inline pair <ll, int> check(int dst, int R, int cord, int pos) { int l = 0, r = 0; for(int step = 1 << 16; step; step >>= 1) { if(l + step <= R && cord - dst > x[l + step]) { l += step; } if(r + step <= R && cord + dst >= x[r + step]) { r += step; } } pair <ll, int> ans; ans.first = 1LL * (pos - l) * x[pos] - (sp[pos] - sp[l]) + (sp[r] - sp[pos]) - 1LL * (r - pos) * x[pos]; ans.second = r - l; /*if(pos == 1) { cerr << dst << " " << l + 1 << " " << r << " " << ans.first << " " << ans.second << "\n"; }*/ return ans; } int besthub(int R, int L, int X[], long long B) { x.resize(R + 1), sp.resize(R + 1); for(int i = 1; i <= R; i++) { x[i] = X[i - 1]; sp[i] = sp[i - 1] + x[i]; } ll ans = 0; for(int i = 1; i <= R; i++) { int dst = 0; for(int step = 1 << 30; step; step >>= 1) { if(check(dst + step, R, x[i], i).first < B) { dst += step; } } auto cur = check(dst, R, x[i], i); dst++; ans = max(ans, cur.second + (B - cur.first) / dst); //cerr << i << " " << cur.first << " " << cur.second << " " << dst << "\n"; } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...