"bzoj3676" [Apio2014] palindrome series Palindrome automatic Machine

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.