bzoj3676 [Apio2014] palindrome string

Source: Internet
Author: User

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 "Example inputs L"
Abacaba

"Sample input 2]
Www
Sample Output "Example outputs L"
7

Sample Output 2]
4
HINT

A string is a palindrome when and only if it reads from left to right and reads from right to left exactly the same.
In the first example, there are 7 palindrome substrings: A,b,c,aba,aca,bacab,abacaba, wherein:
A appears 4 times with a value of 4:1:1=4
B appears 2 times with a value of 2:1:1=2
C appears 1 times with a value of l:1:l=l
ABA appears 2 times with a value of 2:1:3=6
ACA appears 1 times with a value of 1=1:3=3
Bacab appears 1 times with a value of 1:1:5=5
Abacaba appears 1 times with a value of 1:1:7=7
Therefore, the maximum palindrome string occurrence value is 7.


"Data size and scoring"
The data satisfies the 1≤ string length ≤300000.

Positive solution: Palindrome automatic machine.

Training Team paper appeared in the Palindrome automatic machine This kind of advanced things, so learned a bit, in fact, quite simple.

This question is directly constructs the palindrome automaton, counts each palindrome string to appear the number of times, takes a maximum value on the line. There's nothing to say.

1#include <algorithm>2#include <iostream>3#include <cstring>4#include <cstdlib>5#include <cstdio>6#include <cmath>7 #defineN (300010)8 #defineIl inline9 #defineRG RegisterTen #definell Long Long One   A using namespacestd; -   - intch[n][ -],f[n],v[n],l[n],n,la,tot; the CharS[n]; - ll ans; -  -IlvoidAdd (RGintC,rgintN) { +RgintX=la; while(s[n-l[x]-1]!=s[n]) x=F[x]; -     if(!Ch[x][c]) { +RgintV=++TOT,K=F[X]; l[v]=l[x]+2; A      while(s[n-l[k]-1]!=s[n]) k=F[k]; atf[v]=ch[k][c],ch[x][c]=v; -     } -v[la=ch[x][c]]++;return; - } -   -IlvoidWork () { inscanf"%s", s+1), N=strlen (s+1), l[++tot]=-1, f[0]=1; -      for(RGintI=1; i<=n;++i) Add (s[i]- the, i); to      for(RGintI=tot;i;--i) Ans=max (Ans,1ll*l[i]*v[i]), v[f[i]]+=V[i]; +printf"%lld\n", ans);return; - } the   * intMain () { $ Work ();Panax Notoginseng     return 0; -}

bzoj3676 [Apio2014] palindrome string

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.