이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define db long double
int n;
bool qry(int x) {
cout << "? " << x << endl;
bool ans; cin >> ans;
return ans;
}
bool chck(int st) {
int ps = st, drc = -1;
int lw = 1, hg = n;
while (lw != hg) {
int md = (lw + hg) / 2;
ps += drc * md;
if (ps < 1 || n < ps) return false;
lw = md + 1;
drc *= -1;
}
return true;
}
int gt_st() {
int st = roundl(n * (db) 2 / 3);
for (int i = st - 100; i <= st + 100; i++)
if (chck(i)) return i;
assert(false);
}
int bn_srch(int st) {
int ps = st; qry(ps);
int add = 0, drc = -1, lw = 1, hg = n;
while (lw != hg) {
int hlf = (hg - lw + 1) / 2;
ps += drc * (hlf + add);
if (qry(ps)) hg = lw + hlf - 1;
else {
add += hlf;
lw = lw + hlf;
}
drc *= -1;
}
return lw;
}
signed main() {
cin >> n;
int ans = bn_srch(gt_st());
cout << "= " << ans << endl;
}
# | 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... |