#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
const int N = 500010;
int len, mgap, ans;
int nxt[N], l[N], r[N], fa[N];
bool vst[N];
bool path[N];
char a[N];
std::vector<int> es[N];
void dfs(int x) {
vst[x] = true;
if (path[x] && x >= mgap) {
ans = std::min(ans, x);
}
for (int i=0; i<es[x].size(); i++) {
int v=es[x][i];
if (path[v]) continue;
else dfs(v);
}
if (l[x] != 0 && r[x] != len+1) {
mgap=std::max(mgap, r[x] - l[x]);
}
r[l[x]] = r[x];
l[r[x]] = l[x];
for (int i=0; i<es[x].size(); i++) {
int v=es[x][i];
if (path[v]) dfs(v);
}
}
signed main() {
scanf("%s", a+1);
len = strlen(a+1);
ans=len;
int j=0;
es[0].push_back(1);
for (int i=2; i<=len; i++) {
while (j && a[j+1] != a[i]) {
j = nxt[j];
}
if (a[j+1] == a[i]) {
j++;
}
nxt[i] = j;
es[j].push_back(i);
}
for (int i=1; i<=len; i++) {
l[i] = i-1;
r[i] = i+1;
}
int cur=len;
while (cur) {
path[cur]=true;
cur=nxt[cur];
}
mgap=1;
dfs(0);
printf("%d\n", ans);
return 0;
}剪贴板
剪贴板 lr2dbas5
剪贴板信息
剪贴板信息
- 收录
- 更新