# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
728122 | nguyentunglam | The Big Prize (IOI17_prize) | C++17 | 71 ms | 5308 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<bits/stdc++.h>
using namespace std;
#include "prize.h"
//mt19937 rng(172831923);
////mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//int rnd(int l, int r) {
// return l + rng() % (r - l + 1);
//}
const int N = 2e5 + 10;
vector<int> ans[N];
int worst;
int check(int i, int j) {
if (ans[i].empty()) ans[i] = ask(i); if (ans[j].empty()) ans[j] = ask(j);
if (ans[j][0] + ans[j][1] != worst) return 2;
int tmp = ans[i][1] + ans[j][0] - worst;
return tmp > 0;
}
int find_best(int n) {
int T = max(1, n / 785);
for(int i = 0; i < n; i += T) {
ans[i] = ask(i);
worst = max(worst, ans[i][0] + ans[i][1]);
}
for(int i = 1; i < n; i++) if (i % T) {
if (ans[i].empty()) ans[i] = ask(i);
if (ans[i][0] + ans[i][1] != worst) continue;
int l = i, r = n - 1;
for(int j = T; j < n; j += T) if (j > i) {
if (check(i, j)) {
r = j;
break;
}
l = j;
}
int last = l;
while (l <= r) {
int mid = l + r >> 1;
int tmp = check(i, mid);
if (!tmp) {
last = mid;
l = mid + 1;
}
else r = mid - 1;
}
// cout << i << " " << last << endl;
i = last;
}
for(int i = 0; i < n; i++) if (!ans[i].empty() && ans[i][0] + ans[i][1] == 0) {
return i;
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |