Bare palindrome Automatic Machine
3676: [Apio2014] palindrome string time limit: Sec Memory Limit: MB
Submit: 504 Solved: 152
[Submit] [Status] [Discuss] 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
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.
Source
[Submit] [Status] [Discuss]
HOME Back
/* ***********************************************author:ckbosscreated time:2015 April 17 Friday 22:29 19 seconds file Name : bzoj3676.cpp************************************************ * * #include <iostream> #include <cstdio># Include <cstring> #include <algorithm> #include <string> #include <cmath> #include <cstdlib > #include <vector> #include <queue> #include <set> #include <map>using namespace Std;typedef Long long int ll;const int maxn=330000;const int c=30;int next[maxn][c];int fail[maxn];int CNT[MAXN]; The number of occurrences of a palindrome string in essence (count after) int NUM[MAXN]; Indicates the most right end of the longest palindrome string represented by node I is the number of palindrome strings at the end of the palindrome string int LEN[MAXN]; Node I represents the length of the palindrome string int S[MAXN]; The character of the node I exists int last; A new letter is formed after the longest palindrome string represented by the node int p; The number of added nodes P-2 is the number of different palindrome string int n; Add the number of characters int newnode (int x) {for (int i=0;i<c;i++) next[p][i]=0;cnt[p]=0; num[p]=0; Len[p]=x;return p++;} void Init () {p=0;newnode (0); NewNode ( -1); last=0; n=0;s[0]=-1; fail[0]=1;} int get_fail (int x) {while (S[n-len[x]-1]!=s[n]) X=FAIl[x];return x;} void Add (int c) {c-= ' a '; S[++n]=c;int cur=get_fail (last); if (!next[cur][c]) {int now=newnode (len[cur]+2); fail[now]= Next[get_fail (Fail[cur])][c];next[cur][c]=now;num[now]=num[fail[now]]+1;} last=next[cur][c];cnt[last]++;} void Count () {for (int i=p-1;i>=0;i--) cnt[fail[i]]+=cnt[i];} Char Str[maxn];int main () {//freopen ("In.txt", "R", stdin); Freopen ("OUT.txt", "w", stdout), while (scanf ("%s", str)!=eof) {init (); (int i=0,sz=strlen (str); i<sz;i++) Add ( Str[i]); count (); LL ans=1;for (int i=2;i<p;i++) Ans=max (Ans,1ll*len[i]*cnt[i]);p rintf ("%lld\n", ans);} return 0;}
Bzoj 3676: [Apio2014] palindrome series Palindrome automatic Machine