Title Description
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. Please find the largest occurrence in all palindrome substrings of S.
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
Exercises
Palindrome Automatic machine naked problem
About Pam Personal Temporary understanding is not very deep, digging pits to fill.
The only need to count the subtree size of the fail tree, and then multiply the length of the last text string.
#include <cstdio> #include <algorithm> #define N 300010using namespace Std;typedef long Long ll;int next[n][26 ], Fa[n] = {1, 1}, Len[n] = {0,-1}, si[n], tot = 1, last;char str[n];void Insert (int c, int now) {int p = Last;whi Le (Str[now-len[p]-1]! = Str[now]) p = fa[p];if (!next[p][c]) {int q = fa[p];while (Str[now-len[q]-1]! = Str[now]) Q = Fa[q];fa[++tot] = Next[q][c], next[p][c] = tot, Len[tot] = len[p] + 2;} Last = Next[p][c], Si[last] + +;} int main () {int i;ll ans = 0;scanf ("%s", str + 1), for (i = 1; str[i]; i + +) insert (Str[i] – ' A ', I); for (i = tot; I ; 1; I--) ans = max (ans, (LL) si[i] * len[i]), si[fa[i]] + = Si[i];p rintf ("%lld\n", ans); return 0;}
"bzoj3676" [Apio2014] palindrome series Palindrome automatic Machine