1. 程式人生 > >F - The Minimum Length

F - The Minimum Length

F - The Minimum Length

  HUST - 1010 
#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\n",tmp); } }
View Code