# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
316121 | 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));
const int N = 200000 + 7;
vector<int> ret[N];
int sol = -1;
/// delete
vector<int> ask(int i) {
cout << "? " << i << endl;
vector<int> v(2);
cin >> v[0] >> v[1];
return v;
}
vector<int> get(int i) {
if (ret[i].empty()) {
ret[i] = ask(i);
if (ret[i][0] == 0 && ret[i][1] == 0) {
sol = i;
}
}
return ret[i];
}
void after(int n, int pos) {
get(pos);
int cnt = 0, go = pos + 1;
while (go < n) {
int lo = go, hi = n - 1, id = -1;
while (lo <= hi) {
cout << "\t\t\t" << lo << " " << hi << "\n";
int mid = (lo + hi) / 2;
if (get(mid)[0] + get(mid)[1] == get(pos)[0] + get(pos)[1]) {
if (get(mid)[0] == get(pos)[0] + cnt) {
lo = mid + 1;
} else {
id = mid;
hi = mid - 1;
}
} else {
id = mid;
hi = mid - 1;
}
}
if (id == -1) {
break;
}
if (sol != -1) {
return;
}
cnt++;
go = id + 1;
}
}
void before(int n, int pos) {
get(pos);
int cnt = 0, go = pos - 1;
while (go >= 0) {
int lo = 0, hi = go, id = -1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (get(mid)[0] + get(mid)[1] == get(pos)[0] + get(pos)[1]) {
if (get(mid)[1] == get(pos)[1] + cnt) {
hi = mid - 1;
} else {
id = mid;
lo = mid + 1;
}
} else {
id = mid;
lo = mid + 1;
}
}
if (id == -1) {
break;
}
if (sol != -1) {
return;
}
cnt++;
go = id - 1;
}
}
int find_best(int n) {
int m = n / 2;
int r1 = max(0, m - 250);
int r2 = min(n - 1, m + 250);
vector<int> ord;
for (int j = r1; j <= r2; j++) {
ord.push_back(j);
}
int big = 0, pos = -1;
for (auto &i : ord) {
big = max(big, get(i)[0] + get(i)[1]);
}
for (auto &i : ord) {
if (big == get(i)[0] + get(i)[1]) {
pos = i;
}
}
assert(pos != -1);
if (sol != -1) {
return sol;
}
after(n, pos);
if (sol != -1) {
return sol;
}
before(n, pos);
assert(sol != -1);
return sol;
}
int main() {
after(10, 0);
cout << sol << "\n";
}