首先我要吐槽一下HINT..smg 你以为这样说我们就看不出这题是kmp啦...
kmp求出pre数组答案就是n-pre[n]
似乎很显然,可以令
t=n−pre[n]
然后
s[n]=s[n−t]=s[n−2∗t]=s[n−3∗t]....
对于其他的下标也是如此
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<cstdio>
#include<queue>
#include<cmath>
#include<set>
#include<map>
#define N 1000005
using namespace std;
char s[N];
int pre[N],n;
int main()
{
scanf("%d\n",&n);gets(s+1);
int now=0;
pre[1]=0;
for(int i=2;i<=n;i++)
{
while(now&&s[now+1]!=s[i]) now=pre[now];
if(s[now+1]==s[i])now++;
pre[i]=now;
}
cout<<n-pre[n];
return 0;
}