#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define int long long
int n;
bool ask(int i, int sz){
int resp;
cout << "? " << i << ' ' << i+sz-1 << '\n' << flush;
cin >> resp;
return resp==1;
}
void sol(){
cin >> n;
//even sized palindromes
int ans=0;
bool found=0;
int sz=2;
do{
found=0;
for(int i=1;i<=n-sz+1;i++){
if(ask(i,sz)){
found=1;
ans=max(ans,sz);
int l=i, r=i+sz-1;
while(1<=l-1 && r+1<=n){ //expand palin
l--; r++;
if(ask(l,r))ans=max(ans,r-l+1);
}
}
}
}while(found);
//odd sized palindromes
sz=3;
do{
found=0;
for(int i=1;i<=n-sz+1;i++){
if(ask(i,sz)){
found=1;
ans=max(ans,sz);
int l=i, r=i+sz-1;
while(1<=l-1 && r+1<=n){ //expand palin
l--; r++;
if(ask(l,r))ans=max(ans,r-l+1);
}
}
}
}while(found);
cout << "! " << ans << '\n' << flush;
}
signed main(){
int tc=1;
// cin >> tc;
while(tc--) sol();
}
# | 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... |