Description"Madoka, don't believe QB. With Homura's disappointment, Madoka signed a contract with QB. It was a nightmare for Modoka, and it was also what happened in the last cycle. In order to make this one Madoka no longer contract with QB, Homura decided to resolve QB on the first day of school. However, QB has a lot of surrogates too (but in the eighth words the plot shows that it could have been reborn indefinitely.) But a firm Homura will not give up-she has decided to destroy everything that may be QB. Now, she has sensed a near state, and turned it into a string of length n for you to learn OI. Now you know from her words that all the strings that resemble a+b+a are QB or its surrogates, and Len (A) >=k,len (B) >=1 (the position is different with the other characters of the same substring of different substrings, the same position but split different substring count the same substring), and then you have to tell Ho as soon as possible Mura the answer--QB and the number of its surrogates.
InputThe first line is a string, the second line is a number k
OutputOnly one line of ans, indicating the number of QB and its aliases
Sample Input"Sample Input 1"
Aaaaa
1
"Sample Input 2"
Abcabcabc
2
Sample Output"Sample Output 1"
6
"Sample Output 2"
8
HINT
For 100% of the data: n<=15000, k<=100, and the character set is all lowercase letters
A: Enumerates the left endpoints and then expands the KMP.
Code:
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 20000
using namespace Std;
Char S[n],ss[n];
int Ans,k,j,fail[n],len;
int main () {
scanf ("%s", s+1); scanf ("%d", &k); Len=strlen (s+1)
; for (int i=1;i<=len;i++)
if (len-i+1>k*2) {for
(int p=i;p<=len;p++) ss[p-i+1]=s[p];
j=0;
for (int p=2;p<=len-i+1;p++) {while
(J&&ss[j+1]!=ss[p]) j=fail[j];
if (Ss[j+1]==ss[p]) j + +;
fail[p]=j;
}
j=0;
for (int p=1;p<=len-i+1;p++) {while
(J&&ss[j+1]!=ss[p]) j=fail[j];
if (Ss[j+1]==ss[p]) j + +;
int jj=j;
while (jj&& (jj<<1>=p)) JJ=FAIL[JJ];
ans+=jj>=k;
}
cout<<i<< ' <<ans<<endl;
}
cout<<ans<<endl;