自己YY一下可以发现answer = n - fail[ n ] ----------------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #define rep( i , n ) for( int i = 0 ;…
kmp复健,答案是n-next[n] #include<iostream> #include<cstdio> using namespace std; const int N=1000005; int n,ne[N]; char s[N]; int main() { scanf("%d%s",&n,s+1); int j=0; for(int i=2;i<=n;i++) { while(s[j+1]!=s[i]&&j) j=ne[j…