#include "bits/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
<< ": "; \
dbgh(__VA_ARGS__)
#else
#define cerr \
if (false) \
cerr
#define dbg(...)
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
int n;
bool valid(int x) {
return 1 <= x && x <= n;
}
int dfs(int l, int r) {
if (l == r) {
return 1;
}
int mid = (l + r) / 2;
int x = dfs(mid + 1, r);
if (valid(x - mid)) {
return x - mid;
} else {
return x + mid;
}
}
void solve(int l, int r, int prev) {
if (l == r) {
cout << "= " << l << endl;
return;
}
int mid = (l + r) / 2;
int nxt = prev - mid;
if (!valid(nxt)) {
nxt = prev + mid;
}
cout << "? " << nxt << endl;
int x;
cin >> x;
if (x) {
solve(l, mid, nxt);
} else {
solve(mid + 1, r, nxt);
}
}
void solve() {
cin >> n;
int start = dfs(1, n);
dbg(start);
cout << "? " << start << endl;
int x;
cin >> x;
solve(1, n, start);
}
int main() {
ios_base::sync_with_stdio(false);
cin.exceptions(ios::failbit);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
3 |
Incorrect |
1 ms |
208 KB |
Hair color 2 was used multiple times |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
3 |
Incorrect |
1 ms |
208 KB |
Hair color 2 was used multiple times |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
3 |
Incorrect |
1 ms |
208 KB |
Hair color 2 was used multiple times |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
3 |
Incorrect |
1 ms |
208 KB |
Hair color 2 was used multiple times |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
OK (4 queries) |
2 |
Correct |
0 ms |
208 KB |
OK (7 queries) |
3 |
Incorrect |
1 ms |
208 KB |
Hair color 2 was used multiple times |
4 |
Halted |
0 ms |
0 KB |
- |