经典题吧
我觉得我要换个板子,这结构体板子真TM不顺手
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
struct PAM_Trie {
int ch[26];
int fail, len, cnt;
};
struct PAM {
PAM_Trie b[N];
int n, last, cnt, s[N];
PAM() {
b[0].len = 0;
b[1].len = -1;
b[0].fail = 1;
b[1].fail = 0;
last = 0;
cnt = 1;
}
int get_fail(int x) {
while(s[n - b[x].len - 1] != s[n]) {
x = b[x].fail;
}
return x;
}
void insert(char ch) {
s[++n]=ch;
int p = get_fail(last);
if(!b[p].ch[s[n]]) {
b[++cnt].len = b[p].len + 2;
int tmp = get_fail(b[p].fail);
b[cnt].fail = b[tmp].ch[s[n]];
b[p].ch[s[n]] = cnt;
}
last = b[p].ch[s[n]];
b[last].cnt++;
}
} P;
int length;
char c[N];
int main() {
scanf("%s", c + 1);
length = strlen(c + 1);
int k=0;
P.s[0]=26;
for(int i=1;i<=length;i++) {
P.insert(c[i]-'a');
}
long long mx=0;
for(int i=P.cnt;i>=1;--i) {
P.b[P.b[i].fail].cnt += P.b[i].cnt;
mx=max(mx, (long long)P.b[i].len * P.b[i].cnt);
}
cout<<mx<<endl;
}