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;
int find_best(int N) {
int lol = -1, ted = -1, cnt = 0;
vector<vector<int>> a(475);
for (int i = 0; i < 475; i++) {
a[i] = ask(i);
int s = a[i][0] + a[i][1];
if (s == 0) {
return i;
}
lol = max(lol, s);
}
for (int i = 0; i < 475; i++) {
int s = a[i][0] + a[i][1];
if (s < lol) {
cnt++;
ted = max(ted, s);
}
}
int x = 475;
while (cnt < 27) {
vector<int> t = ask(x);
int s = t[0] + t[1];
if (s == 0) {
return x;
}
if (s == lol) {
int lo = x, hi = N - 1;
while (lo < hi) {
int mi = (lo + hi + 1) / 2;
vector<int> v = ask(mi);
if (v == t) {
lo = mi;
} else {
hi = mi - 1;
}
}
x = lo;
} else {
cnt++;
ted = max(ted, s);
}
x++;
}
while (1) {
vector<int> t = ask(x);
int s = t[0] + t[1];
if (s == 0) {
return x;
}
if (s < ted) {
x++;
continue;
}
if (s == lol) {
int lo = x, hi = N - 1;
while (lo < hi) {
int mi = (lo + hi + 1) / 2;
vector<int> v = ask(mi);
if (v == t) {
lo = mi;
} else {
hi = mi - 1;
}
}
x = lo + 1;
} else {
int lo = x, hi = N - 1;
while (lo < hi) {
int mi = (lo + hi + 1) / 2;
vector<int> v = ask(mi);
if (v == t) {
lo = mi;
} else if (v[0] + v[1] == lol) {
int l = lo + 1, r = mi;
while (l < r) {
int m = (l + r) / 2;
vector<int> u = ask(m);
if (u == v) {
r = m;
} else {
l = m + 1;
}
}
if (ask(l - 1) == t) {
lo = mi;
} else {
hi = mi - 1;
}
} else {
hi = mi - 1;
}
}
x = lo + 1;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |