# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
316093 | MrDomino | The Big Prize (IOI17_prize) | C++14 | 0 ms | 0 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>
#include "prize.h"
using namespace std;
mt19937 rng((long long) (new char));
int rn(int l, int r) {
return l + rng() % (r - l + 1);
}
int rep(int l, int r, int q) {
assert(q >= 0);
if (l > r || q == 0) {
return 0;
}
int i = rn(l, r);
vector<int> v = ask(i);
q--;
if (v[0] == 0 && v[1] == 0) {
return i;
}
if (v[0] == 0) {
return rep(i + 1, r, q);
}
if (v[1] == 0) {
return rep(l, i - 1, q);
}
/// cnt(0) / cnt(1) = v[0] / v[1]
/// cnt(0) + cnt(1) = q
ll c0 = (ll) v[0] * q / (v[0] + v[1]);
ll c1 = q - c0;
int x = rep(l, i - 1, (int) c0);
if (x) {
return x;
} else {
return rep(i + 1, r, (int) c1);
}
}
int find_best(int n) {
return rep(0, n - 1, 9000);
}