洛谷P3649 [APIO2014]回文串(回文自动机)

传送门

 

话说回文自动机我自己都还没搞懂呢……

等到时候会了再来填坑

 1 //minamoto
 2 #include<cstdio>
 3 #include<cstring>
 4 #define ll long long
 5 template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
 6 const int N=3e5+5;
 7 char s[N];
 8 int n,p,q,fail[N],cnt[N],len[N],tot,last,ch[N][26];
 9 ll ans;
10 inline int newnode(int x){
11     len[++tot]=x;return tot;
12 }
13 inline int getfail(int x,int n){
14     while(s[n-len[x]-1]!=s[n]) x=fail[x];
15     return x;
16 }
17 int main(){
18     scanf("%s",s+1);
19     s[0]=-1,fail[0]=1,last=0;
20     len[0]=0,len[1]=-1,tot=2;
21     for(int i=1;s[i];++i){
22         s[i]-='a';
23         p=getfail(last,i);
24         if(!ch[p][s[i]]){
25             q=newnode(len[p]+2);
26             fail[q]=ch[getfail(fail[p],i)][s[i]];
27             ch[p][s[i]]=q;
28         }
29         ++cnt[last=ch[p][s[i]]];
30     }
31     for(int i=tot;i;--i)
32     cnt[fail[i]]+=cnt[i],cmax(ans,1ll*cnt[i]*len[i]);
33     printf("%lld\n",ans);
34     return 0;
35 }

 

转载于:https://www.cnblogs.com/bztMinamoto/p/9629587.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值