05 [TEMPLATE] manacher algorithm, p3805manacher Algorithm
Description
Returns the length of a string consisting of lowercase letters a, B, c... y, and z.
String Length: n
Input/Output Format
Input Format:
A string consisting of lowercase letters a, B, c... y, and z.
Output Format:
An integer indicates the answer.
Input and Output sample input sample #1:
aaa
Output sample #1:
3
Description
String Length len <= 11000000
Manacher of Lu Jiao is too low ,,
Write one T,
The bitwise computation type will be changed later.
Only 300 ms at one point
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<queue> 6 #include<algorithm> 7 #include<cstdlib> 8 #define lli long long int 9 using namespace std;10 const lli MAXN=31000011;11 char s[MAXN];12 char str[MAXN];13 int ans[MAXN];14 int len=0;15 int ls=0;16 void getstr()17 {18 str[0]='#';19 str[1]='#';20 for(int i=0;i<ls;i++)21 str[(i<<1)+2]=s[i],str[(i<<1)+3]='#';22 ls=(ls<<1)+2;23 str[ls]=0;24 }25 void manacher()26 {27 getstr();28 int mx=0,id=0;29 30 len=strlen(str);31 for(int i=1;i<len;i++)32 {33 if(mx>i)34 ans[i]=min(ans[2*id-i],mx-i);35 else ans[i]=1;36 while(str[i+ans[i]]==str[i-ans[i]])37 ++ans[i];38 if(i+ans[i]>mx)39 mx=i+ans[i],id=i;40 41 }42 }43 int main()44 {45 scanf("%s",s);46 ls=strlen(s);47 manacher();48 int out=0;49 for(int i=0;i<len;i++)50 out=max(out,ans[i]);51 printf("%d",out-1);52 return 0;53 }