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 <iostream>
using namespace std;
int gogo(int fr, int to, int lc, int rc, int mxc) {
if (lc + rc == mxc) {
return -1;
}
int mid = (fr + to) / 2;
int lto = mid, rfr = mid + 1;
vector<int> res;
int n = to - fr;
for (int i = 0; i < n; i++) {
if (i & 1) {
mid -= i;
} else {
mid += i;
}
lto = min(lto, mid);
rfr = max(rfr, mid + 1);
res = ask(mid);
int c = res[0] + res[1];
if (c == 0) {
return mid;
} else if (c == mxc) {
int lrc, rlc;
if (mid == lto) {
lrc = res[1];
rlc = res[0] + i;
} else {
lrc = res[1] + i;
rlc = res[0];
}
int lrt = gogo(fr, lto, lc, lrc, mxc);
if (lrt != -1) {
return lrt;
} else {
return gogo(rfr, to, rlc, rc, mxc);
}
}
}
return -1;
}
int find_best(int n) {
int mxc = 0;
for(int i = 0; i < n && i < 500; i++) {
std::vector<int> res = ask(i);
if(res[0] + res[1] == 0)
return i;
if (res[0] + res[1] > mxc) {
mxc = res[0] + res[1];
}
}
return gogo(0, n, 0, 0, mxc);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |