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 namespace std;
signed main() {
int n;
cin >> n;
int c;
if (n == 2) {
cout << "? 1" << endl; cin >> c;
cout << "? 2" << endl; cin >> c;
if (c == 1) cout << "= 2" << endl;
else cout << "= 1" << endl;
return 0;
} else if (n == 3) {
cout << "? 2" << endl; cin >> c;
cout << "? 3" << endl; cin >> c;
if (c == 1) cout << "= 1" << endl;
else {
cout << "? 1" << endl; cin >> c;
if (c == 1) cout << "= 2" << endl;
else cout << "= 3" << endl;
}
return 0;
}
int l = 2, r = n+1, t = 0, ans = n, end = 0;
//if (n == 3) r = 5;
cout << "? " << l << "\n";
cin >> c;
while (!end) {
if (t) {
l += 2;
cout << "? " << l << endl;
} else {
r -= 2;
cout << "? " << r << endl;
}
cin >> c;
if (c == 0) break;
else {
ans = min(ans, r - l);
if (ans <= 2) break;
}
t ^= 1;
}
if (c == 1) {
if (ans == 2) {
if (t) {
cout << "? " << r-1 << endl;
} else {
cout << "? " << l+1 << endl;
}
cin >> c;
if (c) ans = 1;
}
cout << "= " << ans << endl;
return 0;
}
while (c == 0) {
if (t) {
r++;
cout << "? " << r << endl;
} else {
l--;
cout << "? " << l << endl;
}
t ^= 1;
cin >> c;
if (c == 1) {
ans = min(ans, r - l);
end = 1;
}
if (c == 0 && (r - l == ans-1)) {
end = 1;
break;
}
}
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... |