# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
692477 | sharaelong | The Big Prize (IOI17_prize) | C++17 | 51 ms | 1888 KiB |
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 long long ll;
typedef pair<int, int> pii;
const int MAX_N = 2e5 + 1;
int trash = 0;
pii res[MAX_N];
void secure_ask(int x) {
if (res[x].first == -1) {
vector<int> tmp = ask(x);
res[x] = { tmp[0], tmp[1] };
}
}
void solve(int l, int r) {
while (l <= r) {
secure_ask(l);
if (res[l].first + res[l].second == trash) break;
l++;
}
while (l <= r) {
secure_ask(r);
if (res[r].first + res[r].second == trash) break;
r--;
}
if (l >= r) return;
int m = (l+r) / 2;
while (m < r) {
secure_ask(m);
if (res[m].first + res[m].second == trash) {
if (res[l].first < res[m].first) solve(l, m);
if (res[m].first < res[r].first) solve(m, r);
return;
}
m++;
}
m = (l+r) / 2;
while (m > l) {
secure_ask(m);
if (res[m].first + res[m].second == trash) {
if (res[l].first < res[m].first) solve(l, m);
if (res[m].first < res[r].first) solve(m, r);
return;
}
m--;
}
}
int find_best(int n) {
memset(res, -1, sizeof res);
int rtn = sqrt(n);
for (int i=rtn; i<n; i+=rtn) {
vector<int> tmp = ask(i);
if (tmp[0] + tmp[1] == 0) return i;
trash = max(trash, tmp[0]+tmp[1]);
res[i] = { tmp[0], tmp[1] };
}
for (int i=rtn; i<n; i+=rtn) solve(i-rtn, i);
solve(n-1-rtn, n-1);
for (int i=0; i<n; ++i) {
if (res[i].first + res[i].second == 0) {
return i;
}
}
assert(false);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |