3676: [Apio2014] palindrome string time limit:20 Sec Memory limit:128 MB
submit:2665 solved:1164
[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
Idea {palindrome automatic machine naked problem ah! The direct structure of the palindrome automatic statistical nature of the different strings of how many, and then one by one to compare. }
#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include < cstdio> #include <vector> #include <cmath> #include <queue> #include <stack> #include <map > #include <set> #define INF (1<<30) #define IL inline#define RG register#define LL long Long#define Maxx 3000 10using namespace Std;char s[maxx];int nxt[maxx][28],cnt[maxx],f[maxx],num[maxx],len[maxx],l,cc; LL ans;il void Insert (RG int N,RG int c) {RG int p=l;while (S[n-len[p]-1]!=s[n]) p=f[p];if (!nxt[p][c]) {len[++cc]=len[p]+2; RG int pp=f[p];while (s[n-len[pp]-1]!=s[n]) pp=f[pp];f[cc]=nxt[pp][c],nxt[p][c]=cc;} l=nxt[p][c];cnt[l]++;} Il void count () {for (RG int i=cc;i!=1;--i) cnt[f[i]]+=cnt[i];} Il void Getans () {for (RG int i=cc;i!=1;i--) Ans=max (Ans, (LL) len[i]*cnt[i]);p rintf ("%lld", Ans);} Il void work () {scanf ("%s", s+1); RG int Len=strlen (s+1); f[0]=1,len[++cc]=-1;for (RG int i=1;i<=len;++i) Insert (i,s[i]-' a ' + 1); count (); Getans ();} int main () {work (); return 0;}
BZOJ3676:[APIO2014] Palindrome string