### 正解

```#include <bits/stdc++.h>
#define N 200005

using namespace std;
typedef unsigned long long ULL;

const int base = 127;

unordered_map<ULL, int> las;

int n, k, ans;
char s[N];
ULL ha[N], pw[N];
int f[N];

int x = 0;
char ch = getchar();
while (!isdigit(ch))
ch = getchar();
while (isdigit(ch))
x = x * 10 + ch - '0', ch = getchar();
return x;
}

ULL calc(int l, int r) {
return ha[l] - pw[r - l + 1] * ha[r + 1];
}

int check(int x) {
f[0] = 0;
int res = 0;
for (int i = 1; i <= n - x + 1; i++) {
if (i - x > 0)
las[calc(i - x, i - 1)] = i - x;
f[i] = f[las[calc(i, i + x - 1)]] + 1;
res = max(res, f[i]);
}
for (int i = 1; i <= n - x + 1; i++)
las[calc(i, i + x - 1)] = 0;
return res >= k;
}

int main() {
scanf("%s", s + 1);

ha[n + 1] = 0;
for (int i = n; i >= 1; i--)
ha[i] = ha[i + 1] * base + s[i] - 'a';

pw[0] = 1;
for (int i = 1; i <= n; i++)
pw[i] = pw[i - 1] * base;

int l = 1, r = n;
while (l <= r) {
int mid = (l + r) / 2;
if (check(mid)) {
ans = max(ans, mid);
l = mid + 1;
} else {
r = mid - 1;
}
}

printf("%d\n", ans);
return 0;
}```