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"
using namespace std;
int _n, ans;
bool lollipop(int k) { return k * 2 >= _n; }
bool dnc(int l, int r, int cntl, int cntr) {
if (l > r) return false;
int m = (l + r) >> 1;
int p = m;
vector<int> a;
while (p <= r) {
a = ask(p);
if (a[0] + a[1] == 0) { ans = p; return true; }
if (lollipop(a[0] + a[1])) break;
++p;
}
if (p <= r) {
// [l, m-1] and [p+1, r]
if (a[0] - (p - m) > cntl && dnc(l, m - 1, cntl, a[1] + (p - m))) return true;
if (a[1] > cntr && dnc(p + 1, r, a[0], cntr)) return true;
}
else {
if (dnc(l, m - 1, cntl, cntr + (p - m))) return true;
}
return false;
}
int find_best(int N) {
_n = N;
dnc(0, _n - 1, 0, 0);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |