| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 434789 | dutch | The Big Prize (IOI17_prize) | C++17 | 0 ms | 0 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 <bits/stdc++.h>
using namespace std;
const int LIM = 480;
int ans, val;
void search(int l, int r, int lx, int rx){
if(l > r || ans >= 0 || lx + rx == val) return;
int m1 = (l + r) / 2, m2 = m1 + 1, x, y, cnt = 0;
vector<int> q = {0, 0};
while(cnt < val - lx - rx){
if((y = m1-l > r-m2)) x = m1--;
else x = m2++;
q = ask(x);
if(q[0] + q[1] == 0) return void(ans = x);
if(q[0] + q[1] < val) ++cnt;
else break;
}
q[!y] += cnt;
search(l, m1, lx, q[1]);
search(m2, r, q[0], rx);
}
int find_best(int n){
ans = val = -1;
map<int, int> c;
for(int i=0; i<min(n, LIM); ++i){
vector<int> q = ask(i);
val = max(val, q[0] + q[1]);
++c[q[0] + q[1]];
if(q[0] + q[1] == 0) return i;
val = max(val, q[0] + q[1]);
}
int cnt = 0;
for(auto [i, j] : c) if(i < val) cnt += j;
if(LIM < n) search(LIM, n-1, cnt, 0);
return ans;
}
