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;
mt19937 rng((long long) (new char));
const int N = 200000 + 7;
vector<int> ret[N];
set<int> s;
int mx;
int sol;
vector<int> get(int i) {
if (ret[i].empty()) {
ret[i] = ask(i);
if (ret[i][0] == 0 && ret[i][1] == 0) {
sol = i;
}
}
return ret[i];
}
bool is(int x) {
return get(x)[0] + get(x)[1] == mx;
}
int rep(int l, int r) {
if (l > r) {
return 0;
}
auto it = s.lower_bound(r);
if (it != s.end()) {
auto it2 = s.lower_bound(l + 1);
if (it2 != s.begin()) {
it2--;
int f = *it2;
int s = *it;
if (get(f)[0] == get(s)[0]) {
return 0;
}
}
}
int m = (l + r) / 2;
if (get(m)[0] == 0 && get(m)[1] == 0) {
return m;
}
int x = rep(l, m - 1);
if (x == 0) {
x = rep(m + 1, r);
}
return x;
}
int find_best(int n) {
sol = -1;
vector<int> ord(n);
for (int i = 0; i < n; i++) {
ord[i] = i;
}
shuffle(ord.begin(), ord.end(), rng);
while ((int) ord.size() > 100) {
ord.pop_back();
}
mx = 0;
for (auto &x : ord) {
mx = max(mx, get(x)[0] + get(x)[1]);
}
for (auto &x : ord) {
if (is(x)) {
s.insert(x);
}
}
if (sol != -1) {
return sol;
}
rep(0, n - 1);
}
Compilation message (stderr)
prize.cpp: In function 'int find_best(int)':
prize.cpp:56:20: warning: control reaches end of non-void function [-Wreturn-type]
56 | vector<int> ord(n);
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |