이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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) {
++l, ++r;
cout << "? " << l << " " << r << endl;
int ret;
cin >> ret;
return ret;
};
int cur = 1;
int res = 1;
auto SolveOdd = [&](int it) {
int lowOdd = it - cur;
int highOdd = it + cur;
bool foundOdd = false;
while (lowOdd >= 0 && highOdd < n && Ask(lowOdd, highOdd) == 1) {
foundOdd = true;
lowOdd -= 1;
highOdd += 1;
cur += 1;
}
if (foundOdd) {
cur -= 1;
res = max(res, cur * 2 + 1);
cur += 1;
}
return ;
};
auto SolveEven = [&](int it) {
bool foundEven = false;
int lowEven = it - cur + 1;
int highEven = it + cur;
while (lowEven >= 0 && highEven < n && Ask(lowEven, highEven) == 1) {
foundEven = true;
lowEven -= 1;
highEven += 1;
cur += 1;
}
if (foundEven) {
cur -= 1;
res = max(res, cur * 2);
cur += 1;
}
};
for (int i = 0; i < n; i++) {
SolveOdd(i);
}
for (int i = 0; i < n; i++) {
SolveEven(i);
}
cout << "! " << res << 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... |