Cod sursa(job #1260248)

Utilizator bogdanpaunFMI Paun Bogdan Gabriel bogdanpaun Data 11 noiembrie 2014 01:17:04
Problema Substr Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#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;
}