#include<iostream>
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=200010;
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=0, r=0, mx=0;
forsn(i, 1, 2*n){
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)>>1)<<1) + 1);
else mx = max(mx, ((len[i]>>1)<<1));
}
printf("%d\n", mx);
}
Compilation message
Main.cpp: In function 'bool isPalindrome(int, int)':
Main.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%d", &ret);
| ~~~~~^~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
246 ms |
300 KB |
invalid token |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
246 ms |
300 KB |
invalid token |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1377 ms |
676 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
246 ms |
300 KB |
invalid token |
2 |
Halted |
0 ms |
0 KB |
- |