이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
typedef long double ld;
const ll inf = 1e9;
const ld eps = 1e-8;
const ll logs = 32;
#include <cmath>
ll c(ll k) {
cout << "? " << k << endl;
ll x;
cin >> x;
return x;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
ll lsz = 0, rsz = n;
ll va = n / 2, lva;
ll dif = n / 2;
ll left = 0, right = 0;
ll t = 1;
while (dif > 1) {
lva = va;
va = (va + n) / 2;
dif = va -lva;
if (t)
left += dif;
else
right += dif;
t = 1 - t;
}
ll last;
if (!t)
last = left + 1;
else
last = n - (n / 2) - right;
ll x = c(last);
set<ll> st = {last};
while (rsz - lsz > 1) {
ll sz = (rsz + lsz) / 2;
ll ind;
ll var1 = last + sz, var2 = last - sz;
if (st.find(var1) != st.end() || var1 > n)
ind = var2;
else if (st.find(var2) != st.end() || var2 <= 0)
ind = var1;
else if (var2 > (n + 1 - var1))
ind = var2;
else
ind = var1;
x = c(ind);
st.insert(ind);
if (x == 1) {
rsz = sz;
} else
lsz = sz;
last = ind;
}
cout << "= " << rsz << 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... |