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 <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int num_q;
map<int, vi> memo;
vi query(int x) {
if (memo.count(x)) return memo[x];
num_q++;
vi ret = ask(x);
return memo[x] = ret;
}
int find_best(int n) {
memo.clear();
num_q = 0;
for (int i = 0, j; i < n; i = j + 1) {
if (i == n - 1) return i;
j = i;
vi cur = query(i);
if (cur[0] + cur[1] == 0) return i;
int lo = i + 1, hi = n - 1;
while (lo <= hi) {
int mid = (lo + hi) >> 1;
if (query(mid) == cur) {
lo = mid + 1;
j = mid;
} else {
hi = mid - 1;
}
}
}
return -1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |