Len <1000000;
f[i]= min (f[2*j-i],f[j]-2* (i-j)); J for less than I = > J+F[J]/2 max;
#include <iostream>#include<algorithm>#include<string.h>#include<cstdio>#include<vector>using namespacestd;Const intMAXN =1000005*2;CharS[MAXN];CharSTR[MAXN];intans;intF[MAXN];voidSolveintN) {f[0]=1; intMa =0; for(intI=1; i<n; i++) { intd=ma*2-i; intlos=0; if(d<0) {Los=0; } Elselos=F[d]; if(d>=0&&f[ma]-(I-MA) *2<0) {Los=0; } Else if(d>=0) Los=min (los,f[ma]-(I-MA) *2); F[i]=Los; if(i+f[i]/2> ma+f[ma]/2) Ma=i; intL = i-los/2, r=los/2+i; while(L-1>=0&&r+1<n&&str[l-1]==str[r+1]) {L--; r++; } d=r-l+1; F[i]=D; if(i+f[i]/2> ma+f[ma]/2) ma=i; if(str[i]=='#') {D--; if(d>0&&str[l]!='#') {ans=max (2+max ((d2)/2,0), ans); } Else if(d>0) {ans=max (d/2, ans); } } Else { if(d>2&&str[l]!='#') {ans=max (ans,1+ (d1)/2) ; } Else if(d>2) {ans=max (ans,1+ (d3)/2); } } }}intMain () {intCAs; scanf ("%d",&CAs); for(intCC =1; CC <=cas; Cc++) {scanf ("%s", s); intn =strlen (s); intLoc=0; for(intI=0; i<n; i++) {Str[loc++]=S[i]; Str[loc++]='#'; } ans=1; Solve (Loc-1); printf ("%d\n", ans); } return 0;}
View Code
Longest palindrome substring