码迷,mamicode.com
首页 > 其他好文 > 详细

[bzoj]

时间:2017-06-01 22:42:27      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:opened   ide   lld   clu   main   oid   src   class   int   

 

技术分享
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=300010;
char s[maxn];
int l,len,sz;
long long ans;
struct trees{int fail,len,t[27],num,defail;}t[maxn];
int getfail(int x)
{
    while(s[len-t[x].len-1]!=s[len])x=t[x].fail;
    return x;
}
void insert()
{
    int x=s[++len]-a;
    l=getfail(l);
    if(!t[l].t[x])
    {
        sz++;t[sz].num=1;
        t[sz].len=t[l].len+2;
        ans=max(ans,1ll*t[sz].len);
        int g=getfail(t[l].fail);
        t[sz].fail=t[g].t[x];
        t[t[g].t[x]].defail=sz;
        t[l].t[x]=sz;
    }
    else
    {
        t[t[l].t[x]].num++;
        ans=max(ans,1ll*t[t[l].t[x]].num*t[t[l].t[x]].len);
    }
    l=t[l].t[x];
}
int main()
{
    scanf("%s",s+1);
    s[0]=-1;sz=1;
    t[0].fail=t[1].fail=1;
    t[1].defail=0;
    t[0].len=0;t[1].len=-1;
    t[0].num=t[1].num=0;
    l=len=0;
    int n=strlen(s+1);
    ans=0;
    for(int i=1;i<=n;i++)insert();
    printf("%lld",ans);
    return 0;
}
View Code

 

[bzoj]

标签:opened   ide   lld   clu   main   oid   src   class   int   

原文地址:http://www.cnblogs.com/onioncyc/p/6930957.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!