#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
int solve(int low, int upp, ii a, ii b) {
while (a.first + a.second != b.first + b.second) {
if (a.first + a.second < b.first + b.second) {
low++;
auto qres = ask(low);
a.first = qres[0];
a.second = qres[1];
if (a.first + a.second == 0) return low;
}
else {
upp--;
auto qres = ask(upp);
b.first = qres[0];
b.second = qres[1];
if (b.first + b.second == 0) return upp;
}
}
if (a.first == b.first) return 0;
int mid = (low + upp) / 2;
auto cres = ask(mid);
ii c = {cres[0], cres[1]};
return solve(low, mid, a, c) + solve(mid, upp, c, b);
}
int find_best(int n) {
if (n < 5000) {
for (int i = 0; i < n; ++i) {
auto a = ask(i);
if (a[0] + a[1] == 0) return i;
}
}
auto qres = ask(0);
ii a = {qres[0], qres[1]};
if (a.first + a.second == 0) return 0;
qres = ask(n - 1);
ii b = {qres[0], qres[1]};
if (b.first + b.second == 0) return n - 1;
return solve(0, n - 1, a, b);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
answer is not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
answer is not correct |
2 |
Halted |
0 ms |
0 KB |
- |