F - The Minimum Length
Posted cangt-tlan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了F - The Minimum Length相关的知识,希望对你有一定的参考价值。

#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int len; char s[1000010]; int net[1000010]; void getnet(){ memset(net,0,sizeof(net)); net[0]=-1; int k=-1,j=0; while(j<len){ if(k==-1||s[k]==s[j]){ j++;k++; net[j]=k; } else k=net[k]; } } int main(){ while(scanf("%s",s)!=EOF){ len=strlen(s); getnet(); int tmp=len-net[len]; printf("%d ",tmp); } }
以上是关于F - The Minimum Length的主要内容,如果未能解决你的问题,请参考以下文章