标签:size efi targe while iostream ring nan fine \n
代码:
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #define max(a,b) ((a)>(b)?(a):(b)) 5 #define min(a,b) ((a)<(b)?(a):(b)) 6 using namespace std; 7 const int maxn=11000000+50; 8 int len,N,mr,mid,RL[maxn<<1],ans=1; 9 char S[maxn<<1],a[maxn]; 10 inline void Manacher(){ 11 mr=mid=0; 12 for(int i=1;i<=len;i++){ 13 if(i<mr) RL[i]=min(RL[(mid<<1)-i],mr-i); 14 else RL[i]=1; 15 while(i-RL[i]>=1&&i+RL[i]<=len&& 16 S[i-RL[i]]==S[i+RL[i]])RL[i]++; 17 if(i+RL[i]-1>mr){ 18 mr=i+RL[i]-1; 19 mid=i; 20 } 21 ans=max(ans,RL[i]-1); 22 } 23 return; 24 } 25 int main(){ 26 scanf("%s",a); 27 N=strlen(a); 28 S[len=1]=‘#‘; 29 for(int i=0;i<N;i++){ 30 S[++len]=a[i]; 31 S[++len]=‘#‘; 32 } 33 Manacher(); 34 printf("%d\n",ans); 35 return 0; 36 }
By:AlenaNuna
Manacher || Luogu P3805【模板】manacher算法
标签:size efi targe while iostream ring nan fine \n
原文地址:https://www.cnblogs.com/AlenaNuna/p/10887960.html