# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
316307 | nikatamliani | The Big Prize (IOI17_prize) | C++14 | 3093 ms | 4992 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"
vector < vector < int > > memo;
vector < int > memo_ask(int x) {
if(!memo[x].empty()) return memo[x];
return memo[x] = ask(x);
}
int find_best(int n) {
int next = -1, at_most = min(472, n - 1);
const int BLOCK_SIZE = 500;
vector < int > bad(2);
memo.resize(n);
for(int i = 0; i <= at_most; ++i) {
vector < int > cur = memo_ask(i);
if(bad[0] + bad[1] < cur[0] + cur[1]) bad = cur;
if(cur[0] == 0 && cur[1] == 0) return i;
}
int limit = 40, cnt = 0, max_sum = 0;
int sum = bad[0] + bad[1];
for(int i = at_most + 1; i < n; i = next + 1) {
int l = i, r = n - 1; next = -1;
vector < int > t = memo_ask(i);
if(t[0] + t[1] != bad[0] + bad[1] && cnt <= limit) {
++cnt;
max_sum = max(max_sum, t[0] + t[1]);
next = i;
if(t[0] == 0 && t[1] == 0) return i;
continue;
}
if(cnt > limit) sum = max_sum;
int maybe = i + BLOCK_SIZE;
if(maybe < n && memo_ask(maybe)[0] + memo_ask(maybe)[1] >= sum) {
next = maybe;
continue;
}
if(maybe < n) r = maybe - 1;
while(r >= l) {
int m = l + r >> 1;
vector < int > x = memo_ask(m);
if(x[0] + x[1] >= sum) {
next = m;
l = m + 1;
} else {
r = m - 1;
}
}
assert(next >= i);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |