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 "prize.h"
#include<bits/stdc++.h>
using namespace std;
int find_best(int n) {
vector<vector<int>> info(n);
map<int, int> found;
auto get = [&](int i) -> vector<int> {
if (info[i].size())
return info[i];
info[i] = ask(i);
found[info[i][0] + info[i][1]]++;
// for (int i = 0; i < n; ++i)
// cerr << info[i].size() << ' ';
// cerr << '\n';
return info[i];
};
auto findNext = [&](int l, int r, int cur) -> int {
int lo = l, hi = r, x = -1;
while (lo <= hi) {
int md = (lo + hi) / 2;
if (get(md)[0] + get(md)[1] > cur) {
if (get(md)[0] <= found[cur]) {
x = md;
lo = md + 1;
}
else {
hi = md - 1;
}
}
else if (get(md)[0] + get(md)[1] < cur) {
if (get(md)[0] == 0)
return md;
else
hi = md - 1;
}
else {
if (get(md)[0] == 0) {
found[cur] += get(md)[1] - get(l - 1)[1] - 1;
return md;
}
else {
hi = md - 1;
}
}
}
return x;
};
found[0] = 0;
int l = 0, r = n - 1;
get(0);
while (!found[0]) {
l = findNext(l + 1, r, get(l)[0] + get(l)[1]);
// cerr << l << '\n';
if (l == -1) break;
}
for (int i = 0; i < n; ++i) {
if (info[i].size() && info[i][0] + info[i][1] == 0)
return i;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |