이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Sylwia Sapkowska
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define int long long
typedef pair<int, int> T;
const int oo = 1e18, oo2 = 1e9+7, K = 30;
const int mod = 998244353;
void solve(){
int n; cin >> n;
int mid = (1+n)/2;
int l = (mid+1)/2;
int len = 1;
while (len<=n) len*=2;
len/=2;
int r = min(n, l+len);
debug(1, l, r, n);
int ans = oo;
int prev = oo;
auto ask = [&](int x){
cout << "? " << x << "\n";
cout.flush();
bool a; cin >> a;
if (a) {
ans = min(ans, abs(x-prev));
debug(x, prev);
}
prev = x;
return a;
};
ask(l);
bool what = ask(r);
bool right = 1;
while (len>1){
len/=2;
debug(l, r, len);
if (!what){
if (right){
l = max(1LL, l-len);
what = ask(l);
} else {
r = min(n, r+len);
what = ask(r);
}
} else {
if (right){
l = min(n, l+len);
what = ask(l);
} else {
r = max(1LL, r-len);
what = ask(r);
}
}
right ^= 1;
}
debug(l, r);
cout << "= " << ans << "\n";
cout.flush();
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) solve();
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... |