牛客多校3

链接

https://www.nowcoder.com/acm/contest/141/E

题意

懒得描述

题解

直觉是hash,标程给的也是hash,然后也T了。但思索一下可以发现是找循环节,用KMP处理就ok了。

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

#include <bits/stdc++.h>
using namespace std;

int nxt[1000006];
void (char x[],int m)
{
int i,j;
j=nxt[0]=-1;
i=0;
while(i<m)
{
while(-1!=j&&x[i]!=x[j]) j=nxt[j];
nxt[++i]=++j;
}
}
char s[1000005];
int main()
{
scanf("%s",s);
int len=strlen(s);
kmp_pre(s,len);
int l=len-nxt[len];
if(len%l==0&&l!=len)
{
printf("%dn",l);
for(int i=0;i<l;i++)
{
printf("%d",len/l);
for(int j=i;j<len;j+=l)
{
printf(" %d",j);
}
printf("n");
}
}else{
printf("%dn",len);
for(int i=0;i<len;i++)
{
printf("1 %dn",i);
}
}
return 0;
}