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 pair<int, int> ii;
int solve(int low, int upp, ii a, ii b) {
while (a.first + a.second != b.first + b.second) {
if (a.first + a.second < b.first + b.second) {
low++;
if (low < upp) {
auto qres = ask(low);
a = {qres[0], qres[1]};
if (a.first + a.second == 0) return low;
}
else a = b;
}
else {
upp--;
if (low < upp) {
auto qres = ask(upp);
b = {qres[0], qres[1]};
if (b.first + b.second == 0) return upp;
}
else b = a;
}
}
if (a.first == b.first) return 0;
int mid = (low + upp) / 2;
auto cres = ask(mid);
ii c = {cres[0], cres[1]};
if (c.first + c.second == 0) return mid;
return solve(low, mid, a, c) + solve(mid, upp, c, b);
}
int find_best(int n) {
if (n < 5000) {
for (int i = 0; i < n; ++i) {
auto a = ask(i);
if (a[0] + a[1] == 0) return i;
}
}
auto qres = ask(0);
ii a = {qres[0], qres[1]};
if (a.first + a.second == 0) return 0;
qres = ask(n - 1);
ii b = {qres[0], qres[1]};
if (b.first + b.second == 0) return n - 1;
return solve(0, n - 1, a, b);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |