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 "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
int find_best(int n) {
vector<pii> cur, nxt;
cur.emplace_back(0, n-1);
while (!cur.empty()) {
nxt.clear();
sort(cur.begin(), cur.end(), [&] (pii& a, pii& b) {
int sza = a.second-a.first;
int szb = b.second-b.first;
if (sza != szb) return sza < szb;
return a.first < b.first;
});
for (auto& p : cur) {
int l = p.first, r = p.second;
if (l == r) {
vector<int> res = ask(l);
if (res[0] == 0 && res[1] == 0) {
return l;
}
} else {
int m = (l + r) / 2;
vector<int> res = ask(m);
if (res[0] == 0 && res[1] == 0) {
return m;
} else if (res[0] == 1 && res[1] == 0) {
nxt.emplace_back(l, m);
} else if (res[0] == 0 && res[1] == 1) {
nxt.emplace_back(m+1, r);
} else {
nxt.emplace_back(l, m);
nxt.emplace_back(m+1, r);
}
}
}
swap(cur, nxt);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |