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;
typedef long long ll;
int main() {
int n; cin>>n;
int ans=1;
for (int i=1; i<n; i++) {
cout<<"? "<<i<<" "<<i+1<<endl;
cout.flush();
int a; cin>>a;
if (a) {
ans=max(ans,2);
int l=i,r=i+1;
while (true) {
l--; r++;
if (l<1||r>n) break;
cout<<"? "<<l<<" "<<r<<endl;
cout.flush();
cin>>a;
if (a) {
ans=max(ans,r-l+1);
} else break;
}
}
}
for (int i=1; i<n-1; i++) {
cout<<"? "<<i<<" "<<i+2<<endl;
cout.flush();
int a; cin>>a;
if (a) {
ans=max(ans,3);
int l=i,r=i+2;
while (true) {
l--; r++;
if (l<1||r>n) break;
cout<<"? "<<l<<" "<<r<<endl;
cout.flush();
cin>>a;
if (a) {
ans=max(ans,r-l+1);
} else break;
}
}
}
cout<<"! "<<ans<<endl;
cout.flush();
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... |