可惜没如果=_=
时光的河入海流

1355: [Baltic2009]Radio Transmission

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 1046  Solved: 722
[Submit][Status][Discuss]

Description

给你一个字符串,它是由某个字符串不断自我连接形成的。 但是这个字符串是不确定的,现在只想知道它的最短长度是多少.

Input

第一行给出字符串的长度,1 < L ≤ 1,000,000. 第二行给出一个字符串,全由小写字母组成.

Output

输出最短的长度

Sample Input

8
cabcabca

Sample Output

3

HINT

对于样例,我们可以利用"abc"不断自我连接得到"abcabcabc",读入的cabcabca,是它的子串

Source

当 n%(n-next[n])==0 的时候 n-next[n] 就是当前字符串的最小循环节qwq 这性质好像laj在之前某篇博文里证明过qwq

 1 #include "bits/stdc++.h"
 2 using namespace std;
 3 typedef long long LL;
 4 const int MAX=1e6+5;
 5 char s[MAX];
 6 int len,next[MAX];
 7 void get_next(){
 8     int i,j;
 9     j=next[0]=-1;i=0;
10     while (i<=len){
11         if (j==-1 || s[i]==s[j]) next[++i]=++j;
12         else j=next[j];
13     }
14 }
15 int main(){
16     freopen ("radio.in","r",stdin);freopen ("radio.out","w",stdout);
17     int i,j;
18     scanf("%d\n%s",&len,s);
19     get_next();
20     printf("%d",len-next[len]);
21     return 0;
22 }

 

 

posted on 2017-11-05 13:00  珍珠鸟  阅读(199)  评论(0编辑  收藏  举报