Pagini recente » Cod sursa (job #2646048) | Cod sursa (job #878621) | Cod sursa (job #576576) | Cod sursa (job #156586) | Cod sursa (job #1260248)
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n,m,i,j;
char ch[16399];
struct trie{
int cnt;
trie *fiu[26];
trie(){
memset(fiu,0,sizeof(fiu));
cnt = 0;
}
};
trie *t = new trie,*tmp;
int main()
{
freopen("substr.in" ,"r", stdin);
freopen("substr.out","w", stdout);
scanf("%d %d\n",&n,&m);
scanf("%s",ch);
int mmax=-6;
for(i=0;i<n;++i){
tmp = t;
j=0;
while( true ){
tmp->cnt++;
if( ch[i+j] == '\0' ){
break;
}
if( tmp->cnt >= m )
if( mmax < j ) mmax = j;
if( tmp->fiu[ ch[i+j] -'a' ] == 0){
tmp->fiu[ ch[i+j] -'a' ] = new trie;
}
tmp = tmp->fiu[ ch[i+j] -'a' ];
++j;
}
}
printf("%d\n",mmax);
return 0;
}