Topic Portal
Title Description
A string s consisting of a lowercase English character a,b,c...y,z is given, and the length of the longest palindrome in S is obtained.
String length is n
input/output format
Input format:
A line of lowercase English characters a,b,c...y,z a string s
Output format:
An integer representing the answer
input/Output sampleInput Sample # #:
Aaa
Sample # # of output:
3
Description
String length len <= 11000000
Analysis: Manacher algorithm template, algorithm analysis is not specific, five20 big guy speaks very good, can refer to his blog.
Code:
1 //It is made by Holselee on 30th APR 20182 //luogu.org P38053#include <bits/stdc++.h>4 using namespacestd;5 Const intn=2e7+3e6+7;6 CharS[n],neo[n];intP[n];7 intChange ()8 {9 intlen=strlen (s);Ten intret=0; neo[ret++]='$'; One for(intI=0; i<len;i++) Aneo[ret++]='#', neo[ret++]=S[i]; -neo[ret++]='#'; neo[++ret]=' /';returnret; - } the intManacher () - { - intlen=Change (); - intans=-n,id,mx=0; + for(intI=1; i<=len;i++){ - if(I<MX) P[i]=min (p[id*2-i],mx-i); + Elsep[i]=1; A while(Neo[i-p[i]]==neo[i+p[i]]) p[i]++; atAns=max (ans,p[i]-1); - if(I+P[I]>MX) id=i,mx=i+P[i]; - } - returnans; - } - intMain () in { -scanf"%s", s); toprintf"%d", Manacher ()); + return 0; -}
Rokua P3805 [Template]manacher algorithm [Manacher]