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<iostream>
#include<cassert>
using namespace std;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
const int MAXN=400010;
int n, len[MAXN];
bool isPalindrome(int l, int r){
if(l==r) return true;
if(l==0 || r==2*n) return false;
int ret;
l = (l+2)/2, r = (r+1)/2;
if(l==r) return true;
printf("? %d %d\n", l, r);
fflush(stdout);
scanf("%d", &ret);
return ret;
}
int main(){
scanf("%d", &n);
int l=1, r=1, mx=0;
forsn(i, 1, 2*n){
assert(l+r-i >= 0);
len[i]=max(0, min(r-i, len[l+r-i]));
while(isPalindrome(i-len[i], i+len[i])) ++len[i];
if(i+len[i] > r) l=i-len[i], r=i+len[i];
}
forsn(i, 1, 2*n){
if(i&1) mx = max(mx, (((len[i]-1)/2)*2) + 1);
else mx = max(mx, ((len[i]/2)*2));
}
printf("! %d\n", mx);
}
Compilation message (stderr)
Main.cpp: In function 'bool isPalindrome(int, int)':
Main.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("%d", &ret);
| ~~~~~^~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
# | 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... |