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>
#include <map>
using namespace std;
map<int, map<int, pair<int, int>>> resmap;
void resmap_push(int i, int lc, int rc) {
resmap[lc + rc][i] = {lc, rc};
}
int gogo(int fr, int to, int lc, int rc, int mxc) {
// cout << "go " << fr << ' ' << to << endl;
if (lc + rc == mxc) {
return -1;
}
for (auto &rsmp : resmap) {
auto &mp = rsmp.second;
auto lb = mp.lower_bound(fr);
auto ub = mp.upper_bound(to);
pair<int, int> lres, rres;
// cout << "check " << rsmp.first << endl;
if (lb == mp.begin()) {
// cout << "no lb" << endl;
lres = {0, rsmp.first};
} else {
lb--;
// cout << "lb " << lb->first << endl;
lres = lb->second;
}
if (ub == mp.end()) {
// cout << "no ub" << endl;
rres = {rsmp.first, 0};
} else {
// cout << "ub " << ub->first << endl;
rres = ub->second;
}
if (lres.first == rres.first) {
// cout << "skip" << endl;
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);
resmap_push(mid, res[0], res[1]);
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];
}
return max(gogo(fr, lto, lc, lrc, mxc), gogo(rfr, to, rlc, rc, mxc));
}
}
return -1;
}
int find_best(int n) {
resmap.clear();
int mxc = 0;
int lc = 0;
for(int i = 0; i < n && i < 500; i++) {
std::vector<int> res = ask(i);
resmap_push(i, res[0], res[1]);
lc = res[0];
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);
}
Compilation message (stderr)
prize.cpp: In function 'int find_best(int)':
prize.cpp:78: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... |