#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 || l + 1 == 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 |
1 |
Correct |
2 ms |
252 KB |
Output is correct |
2 |
Incorrect |
2 ms |
308 KB |
Integer -1 violates the range [0, 199999] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
344 KB |
Integer -1 violates the range [0, 199999] |
2 |
Halted |
0 ms |
0 KB |
- |