BZOJ3676:[APIO2014] Palindrome string

Source: Internet
Author: User

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

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.