@[int08](/user/508032)
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
char s[N] = "#";
int64_t res, p, q, top = 1, ch[N][30], f[N], l[N], cnt[N];
int main() {
cin >> s + 1;
int n = strlen(s + 1);
f[0] = 1, l[1] = -1;
for (int i = 1; i <= n; i++) {
while (s[i - l[p] - 1] != s[i])
p = f[p];
int ind = s[i] & 31;
if (!ch[p][ind]) {
l[++top] = l[p] + 2;
q = f[p];
while (s[i - l[q] - 1] != s[i])
q = f[q];
f[top] = ch[q][ind];
ch[p][ind] = top;
}
p = ch[p][ind];
cnt[p]++;
}
for (; top > 1; top--)
cnt[f[top]] += cnt[top],
res = max(res, l[top] * cnt[top]);
cout << res;
}
```
我的思路清奇的奇特代码。实在不行看 oiwiki 去,好像有代码和解析。
by Carroty_cat @ 2024-04-02 12:46:52
@[int08](/user/508032) 我无敌了,我给 `std::string[]` 赋值。
此帖结
by int08 @ 2024-04-02 14:25:49