#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define endl '\n'
#define pl(var) " [" << #var << ": " << (var) << "] "
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "[" << p.first << ", " << p.second << "]"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { cout << "["; for(int i = 0; i < (int)v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";}
ll int n;
int low = 0;
bool query(ll int diff, ll int prev) {
if (prev + diff > n && prev - diff < 1) {
cout << "? 2" << endl;
cout.flush();
int s; cin >> s;
prev = 1;
}
int mult = 1;
if (prev + diff > n) {
mult = -1;
}
assert(prev + mult * diff <= n);
cout << "? " << prev + mult * diff << endl;
cout.flush();
int s; cin >> s;
return (bool)s;
}
void solve() {
cin >> n;
int prev = 1;
query(1, 0);
ll int hi = n - 1;
ll int lo = 1;
ll int ans = n;
while (hi >= lo) {
ll int mid = (hi + lo) / 2;
if (query(mid, prev)) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
prev = mid;
}
cout << "= " << ans << endl;
cout.flush();
}
int main() {
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
int T = 1;
// cin >> T;
while (T--)
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Hair color 1 was used multiple times |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Hair color 1 was used multiple times |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Hair color 1 was used multiple times |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Hair color 1 was used multiple times |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Hair color 1 was used multiple times |
2 |
Halted |
0 ms |
0 KB |
- |