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>
using namespace std;
int find_best(int n) {
int cx = 0;
while (true) {
vector<int> X1 = ask(n - 1 - cx);
int L = cx, R = n, M, maxn = 0, QQ = 18;
vector<int> G = {511, 1023, 4095};
for (int i = 0; i < G.size(); i++) {
vector<int> X2 = ask(n - 1 - min(n - 1, cx + G[i]));
if (X2 != X1) { R = min(n, cx + G[i]); break; }
}
for (int i = 0; i <= 18; i++) { if ((1 << i) >= R - L + 1) { QQ = i; break; } }
for (int i = 0; i < QQ; i++) {
M = (L + R) / 2;
vector<int> R1 = ask(n - 1 - min(n - 1, M));
if (R1[0] + R1[1] == 0) return n - 1 - M;
if (X1 == R1) { L = M; maxn = max(maxn, M); }
else { R = M; }
}
cx = maxn + 2;
}
return -1;
}
Compilation message (stderr)
prize.cpp: In function 'int find_best(int)':
prize.cpp:14:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < G.size(); i++) {
~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |