Description
Consider a string s that contains only the lowercase Latin alphabet. We define the "out" of a substring t of s
The present value is the number of occurrences of T in s multiplied by the length of T. Please find out the most in all palindrome strings of S
Large occurrence value.
Input
Enter only one row for a non-empty string s that contains only a lowercase letter (A-Z).
Output
Outputs an integer that is the largest occurrence of a palindrome substring.
Sample Input"Sample Input L"
Abacaba
"Sample input 2]
Www
Sample Output
"Sample Output L"
7
Sample Output 2]
4
Palindrome Tree template problem, although know can multiply on Sam to blow up
1#include <bits/stdc++.h>2 using namespacestd;3typedefLong Longll;4 Const intn=300010;5 structpam{6 intCnt,last;7 inta[n][ -],sz[n],l[n],f[n];8 CharS[n];9 PAM () {Tencnt=f[0]=f[1]=1; Onel[1]=-1; A } - intGet_fail (intXintLoc) { - while(s[loc-l[x]-1]!=s[loc]) x=F[x]; the returnx; - } - voidInsertintCintLoc) { - intp=Get_fail (last,loc); + if(!A[p][c]) { - intnow=++cnt,k=Get_fail (f[p],loc); +l[now]=l[p]+2; Af[now]=a[k][c];a[p][c]=Now ; at } -last=A[p][c]; -++Sz[last]; - } - ll Calc () { -ll res=0; in for(inti=cnt;i;--i) { -sz[f[i]]+=Sz[i]; toRes=max (res, (LL) sz[i]*l[i]); + } - returnRes; the } * }p; $ intMain () {Panax Notoginsengscanf"%s", P.S); - intn=strlen (P.S); the for(intI=0; i<n;++i) +P.insert (p.s[i]-'a', i); Aprintf"%lld\n", P.calc ()); the return 0; +}
BZOJ3676: [Apio2014] palindrome string