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 <map>
#include <iostream>
using namespace std;
map<int, pair<int, int>> resmp;
pair<int, int> myask(int i) {
if (resmp.find(i) == resmp.end()) {
auto r = ask(i);
resmp[i] = {r[0], r[1]};
}
return resmp[i];
}
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;
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);
auto res = myask(mid);
int c = res.first + res.second;
if (c == 0) {
return mid;
} else if (c == mxc) {
int lrc, rlc;
if (mid == lto) {
lrc = res.second;
rlc = res.first + i;
} else {
lrc = res.second + i;
rlc = res.first;
}
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) {
resmp.clear();
int mxc = 0;
int lc = 0;
for(int i = 0; i < n && i < 500; i++) {
auto res = myask(i);
lc = res.first;
if(res.first + res.second == 0)
return i;
if (res.first + res.second > mxc) {
mxc = res.first + res.second;
}
}
return gogo(0, n, 0, 0, mxc);
}
Compilation message (stderr)
prize.cpp: In function 'int find_best(int)':
prize.cpp:58:9: warning: variable 'lc' set but not used [-Wunused-but-set-variable]
int lc = 0;
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |