Cod sursa(job #2476959)
| Utilizator | Data | 19 octombrie 2019 13:15:23 | |
|---|---|---|---|
| Problema | Substr | Scor | 90 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.59 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("substr.in");
ofstream fout("substr.out");
int n, k, ans;
char *s[30000], c[3000000];
bool cmp(char *x, char *y)
{
return strcmp(x, y) < 0;
}
int main()
{
fin >> n >> k;
fin >> c;
for(int i = 0; i < n; i++)
s[i] = c+i;
sort(s, s+n, cmp);
for(int i = 0; i < n-k; i++)
{
int cnt = 0;
char *x, *y;
x = s[i];
y = s[i+k-1];
while(*x == *y && *x && *y) cnt++, x++, y++;
ans = max(ans, cnt);
}
fout << ans;
return 0;
}
