# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
36591 | ruhanhabib39 | The Big Prize (IOI17_prize) | C++14 | 59 ms | 6968 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>
const int MAXN = 2e5;
std::vector<int> res[MAXN + 10];
std::pair<int,int> get(int i) {
if(!res[i].size()) res[i] = ask(i);
return {res[i][0], res[i][1]};
}
int sum(int i) {
return get(i).first + get(i).second;
}
int ls = 0;
int lowest(int n) {
int mx = 0;
for(int i = 0; i*i < n; i++) {
mx = std::max(mx, sum(i));
}
return mx;
}
int solve(int lo, int hi, int lc, int cc) {
if(!cc || lo > hi) return -1;
if(lo == hi) {
if(sum(lo) == 0) return lo;
else return -1;
}
int ml = (lo + hi) / 2 + 1, mr = (lo + hi) / 2;
int lf;
for(int i = 0; i < hi-lo+1; i++) {
int q;
if(i % 2 == 0) q = --ml;
else q = ++mr;
if(sum(q) == ls) {
if(i % 2 == 0) lf = get(q).first - lc;
else lf = get(q).first - lc - (mr - ml);
break;
} else if(sum(q) == 0) {
return q;
}
}
int rr = solve(lo, ml-1, lc, lf);
if(rr != -1) return rr;
rr = solve(mr+1, hi, lc + (mr - ml) + lf, cc - lf - (mr - ml));
if(rr != -1) return rr;
return -1;
}
int find_best(int n) {
ls = lowest(n);
return solve(0, n-1, 0, ls);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |