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 <bits/stdc++.h>
#include "prize.h"
using namespace std;
typedef pair<int, int> ii;
#define x first
#define y second
int res;
map<int, map<int, ii> > p;
void solve(int l, int r) {
if(res != -1 || l > r) return;
int mid = (l + r) / 2;
vector<int> tmp = ask(mid);
ii val = ii(tmp[0], tmp[1]);
if(val.x == 0 && val.y == 0) {
res = mid;
return;
}
bool canL = 1, canR = 1;
auto nxt = p[val.x + val.y].lower_bound(mid);
if(nxt != p[val.x + val.y].begin()) {
nxt--;
if((*nxt).y.x == val.x) canL = 0;
nxt++;
}
if(nxt != p[val.x + val.y].end()) {
if((*nxt).y.y == val.y) canR = 0;
}
p[val.x + val.y][mid] = val;
if(canL) solve(l, mid - 1);
if(canR) solve(mid + 1, r);
}
int find_best(int n) {
res = -1; p.clear();
solve(0, n - 1);
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |