#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
const int M = 1e5 + 10;
char str[M];
int next[M], dp[M];
int l;
int len[M];
void fail()
{
int i = 0;
int j = -1;
next[0] = -1;
while(i < l)
{
if(str[i] == str[j] || j == -1)
{
i ++;
j ++;
next[i] = j;
}
else
j = next[j];
}
}
int main()
{
scanf("%s", str);
l = strlen(str);
fail();
int tot = 0;
for(int i = next[l]; i > 0; i = next[i])
{
len[tot] = i;
tot ++;
}
for(int i = l; i >= 0; i --)
{
dp[i] ++;
dp[next[i]] += dp[i];
}
printf("%d\n", tot + 1);
for(int i = tot - 1; i >= 0; i --)
printf("%d %d\n",len[i], dp[len[i]]);
printf("%d %d\n", l,dp[l]);
}
Codeforces 432D
最新推荐文章于 2021-08-26 00:27:19 发布