[BZOJ3676][Apio2014]回文串(回文自动机)
2016-12-19 23:39
441 查看
题目描述
传送门题解
回文自动机裸题。不知道什么是回文自动机的安利一下
代码
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #define N 300010 #define LL long long char s ; int n,now,cur,fail[N],cnt[N],len[N],tot,last,ch[N][26]; LL ans; int newnode(int x) { len[tot]=x; return tot++; } int get_fail(int x,int n) { while(s[n-len[x]-1]!=s ) x=fail[x]; return x; } LL Max(LL a,LL b) { return (a>b)?a:b; } int main(){ gets(s+1); s[0]=-1;newnode(0);newnode(-1);fail[0]=1; for(n=1;s ;++n) { s -='a'; cur=get_fail(last,n); if (!ch[cur][s ]) { now=newnode(len[cur]+2); fail[now]=ch[get_fail(fail[cur],n)][s ]; ch[cur][s ]=now; } cnt[last=ch[cur][s ]]++; } for(n=--tot;n>1;--n) cnt[fail ]+=cnt ,ans=Max(ans,(LL)cnt *(LL)len ); printf("%lld\n",ans); }
相关文章推荐
- bzoj3676 [Apio2014]回文串(回文自动机)
- [manacher 后缀自动机 || 回文自动机] BZOJ 3676 [Apio2014]回文串
- [bzoj3676][Apio2014]回文串 回文自动机(回文树)
- 回文自动机 模板 bzoj3676【Apio2014】回文串
- 【APIO2014】回文串 jzoj 3654/洛谷 3649/bzoj 3676 回文树(回文自动机)
- 【bzoj3676】[Apio2014]回文串 回文自动机
- bzoj 3676: [Apio2014]回文串 回文自动机
- [BZOJ]3676 [APIO2014] 回文串 回文自动机
- BZOJ 3676: [Apio2014]回文串 回文自动机
- 【BZOJ3676】[Apio2014]回文串 【回文自动机】
- [BZOJ]3676: [Apio2014]回文串 回文自动机
- bzoj 3676: [Apio2014]回文串 (回文自动机)
- BZOJ3676:[Apio2014]回文串(回文自动机)
- 【bzoj3676】[Apio2014]回文串 —— 回文自动机的学习
- BZOJ 3676 [Apio2014]回文串 回文自动机
- [回文自动机] BZOJ 3676: [Apio2014]回文串
- [回文自动机] BZOJ3676 [Apio2014] . 回文串
- bzoj 3676: [Apio2014]回文串 manachar+后缀自动机+倍增(回文树)
- bzoj 3676: [Apio2014]回文串 -- 回文自动机
- 【回文自动机】bzoj3676 [Apio2014]回文串