"Topic link" http://www.lydsy.com/JudgeOnline/problem.php?id=3676
"The main topic"
Consider a string s that contains only the lowercase Latin alphabet.
We define the "occurrence value" of a substring t of S as the number of occurrences of T in s multiplied by the length of T.
The maximum occurrence value in all palindrome substrings of S.
Exercises
We give a string to establish a palindrome tree, statistics of the occurrence of each palindrome string and length, multiply to take the group large can
Code
#include <cstdio> #include <algorithm> #include <cstring> using namespace std;const int n=300010,s=26; int all,son[n][s],fail[n],cnt[n],len[n],text[n],last,tot;int newnode (int l) {for (int i=0;i<s;i++) son[tot][i]=0; Cnt[tot]=0,len[tot]=l; return tot++;} void Init () {last=tot=all=0; NewNode (0), NewNode (-1); Text[0]=-1,fail[0]=1;} int getfail (int x) {while (Text[all-len[x]-1]!=text[all]) x=fail[x]; return x;} void Add (int w) {text[++all]=w; int X=getfail (last); if (!son[x][w]) {int y=newnode (len[x]+2); Fail[y]=son[getfail (Fail[x])][w]; Son[x][w]=y; }cnt[last=son[x][w]]++;} void Count () {for (int i=tot-1;~i;i--) cnt[fail[i]]+=cnt[i];} Char S[n];int main () {while (~SCANF ("%s", s)) {int N=strlen (s); Init (); for (int i=0;i<n;i++) Add (s[i]-' a '); Count (); Long Long ans=0; for (int i=0;i<tot;i++) Ans=max (Ans,1ll*cnt[i]*len[i]); printf ("%lld\n", ans); }return 0;}
Bzoj 3676 [Apio2014] palindrome string (palindrome tree)