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>
using i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 n;
std::cin >> n;
i64 l = 0, r = n;
std::vector<i64> a;
while (l + 1 < r) {
l = (l + r) / 2;
a.push_back(l);
}
std::reverse(a.begin(), a.end());
i64 dir = 1, pos = 0;
for (auto x : a) {
pos += x * dir;
dir = -dir;
}
auto ask = [&](i64 x) {
std::cout << "? " << x + 1 << std::endl;
int f;
std::cin >> f;
return f;
};
ask(pos);
l = 0, r = n;
while (l + 1 < r) {
i64 mid = (l + r) / 2;
i64 p = pos + dir * mid;
if (ask(p)) {
r = mid;
} else {
l = mid;
}
dir = -dir;
pos = p;
}
std::cout << "= " << r << std::endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |