이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* author: wxhtzdy
* created: 05.07.2022 14:44:38
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
auto Ask = [&](int l, int r) {
cout << "? " << l + 1 << " " << r + 1 << endl;
int x;
cin >> x;
return x;
};
int ans = 1;
for (int i = 1; i < n; i++) {
while (true) {
int l = i - (ans + 1) / 2;
int r = i + (ans + 1) / 2;
if (l < 0 || r >= n || !Ask(l, r)) {
break;
}
ans = r - l + 1;
}
}
for (int i = 0; i + 1 < n; i++) {
while (true) {
int l = i - (ans % 2 == 1 ? (ans - 1) / 2 : ans / 2);
int r = i + 1 + (ans % 2 == 1 ? (ans - 1) / 2 : ans / 2);
if (l < 0 || r >= n || !Ask(l, r)) {
break;
}
ans = r - l + 1;
}
}
cout << "! " << ans << endl;
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... |