标签:include pac clu har turn ace style strlen bsp
求最长回文子串。
#include<bits/stdc++.h> using namespace std; #define ll long long const int MAXN=12000010; char Ma[MAXN*2]; int Mp[MAXN*2]; int Manacher(char s[],int len){ int l=0; Ma[l++]=‘$‘; Ma[l++]=‘#‘; for(int i=0;i<len;i++){ Ma[l++]=s[i]; Ma[l++]=‘#‘; } Ma[l]=‘\0‘; int mxr=0,mid=0; for(int i=0;i<l;i++){ Mp[i]=(i<mxr)?min(Mp[2*mid-i],Mp[mid]+mid-i):1; while(Ma[i+Mp[i]]==Ma[i-Mp[i]])Mp[i]++; if(i+Mp[i]>mxr){ mxr=i+Mp[i]; mid=i; } } int ans=0; for(int i=0;i<l;i++){ ans=max(ans,Mp[i]-1); } return ans; } char s[MAXN]; int main(){ scanf("%s",s); int n=strlen(s); printf("%d\n",Manacher(s,n)); return 0; }
标签:include pac clu har turn ace style strlen bsp
原文地址:https://www.cnblogs.com/Yinku/p/10656746.html