#include <bits/stdc++.h>
using namespace std;
struct pal_tree {
#define sigma 26
struct node {
int len, dep, cnt, slink;
int to[sigma];
node(int _len = 0, int _dep = 0, int _cnt = 0, int _slink = 0) {
len = _len; dep = _dep; cnt = _cnt; slink = _slink;
for (int i = 0; i < sigma; i++) {
to[i] = 0;
}
}
};
int suff; string s;
vector<node> tree;
void init() {
tree.clear(); s = ""; suff = 2;
tree.push_back(node(0, 0, 0, 0));
tree.push_back(node(-1, 0, 0, 1));
tree.push_back(node(0, 0, 0, 1));
}
void add_letter(char c) {
s += c; int len = s.size();
while (c != s[len - 2 - tree[suff].len]) {
suff = tree[suff].slink;
}
int nxt = tree[suff].to[c - 'a'];
if (!nxt) {
nxt = tree.size();
tree[suff].to[c - 'a'] = nxt;
tree.push_back(node(tree[suff].len + 2, 0, 0, 0));
if (suff == 1) {
tree[nxt].slink = 2;
}
else {
int z = tree[suff].slink;
while (c != s[len - 2 - tree[z].len]) {
z = tree[z].slink;
}
tree[nxt].slink = tree[z].to[c - 'a'];
}
tree[nxt].dep = tree[tree[nxt].slink].dep + 1;
}
tree[nxt].cnt++; suff = nxt;
}
void calc_cnt() {
for (int i = tree.size() - 1; i > 2; i--) {
tree[tree[i].slink].cnt += tree[i].cnt;
}
}
node &operator[](int i) {
return tree[i];
}
} pt;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
string s; cin >> s;
pt.init();
for (char i : s) {
pt.add_letter(i);
}
pt.calc_cnt();
long long res = 0;
for (int i = pt.tree.size() - 1; i > 2; i--) {
res = max(res, (long long)(pt.tree[i].len) * pt.tree[i].cnt);
}
cout << res << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
308 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
316 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
0 ms |
332 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
0 ms |
332 KB |
Output is correct |
31 |
Correct |
0 ms |
332 KB |
Output is correct |
32 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
508 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
444 KB |
Output is correct |
10 |
Correct |
0 ms |
312 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2316 KB |
Output is correct |
2 |
Correct |
2 ms |
2316 KB |
Output is correct |
3 |
Correct |
2 ms |
2316 KB |
Output is correct |
4 |
Correct |
2 ms |
2316 KB |
Output is correct |
5 |
Correct |
2 ms |
2316 KB |
Output is correct |
6 |
Correct |
2 ms |
2316 KB |
Output is correct |
7 |
Correct |
2 ms |
2300 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
1392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
16032 KB |
Output is correct |
2 |
Correct |
16 ms |
16048 KB |
Output is correct |
3 |
Correct |
17 ms |
16036 KB |
Output is correct |
4 |
Correct |
16 ms |
16040 KB |
Output is correct |
5 |
Correct |
15 ms |
16040 KB |
Output is correct |
6 |
Correct |
14 ms |
16040 KB |
Output is correct |
7 |
Correct |
14 ms |
16040 KB |
Output is correct |
8 |
Correct |
3 ms |
836 KB |
Output is correct |
9 |
Correct |
6 ms |
4592 KB |
Output is correct |
10 |
Correct |
15 ms |
16020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
62916 KB |
Output is correct |
2 |
Correct |
52 ms |
63008 KB |
Output is correct |
3 |
Correct |
53 ms |
62976 KB |
Output is correct |
4 |
Correct |
54 ms |
62892 KB |
Output is correct |
5 |
Correct |
52 ms |
62848 KB |
Output is correct |
6 |
Correct |
51 ms |
62900 KB |
Output is correct |
7 |
Correct |
37 ms |
31724 KB |
Output is correct |
8 |
Correct |
8 ms |
1492 KB |
Output is correct |
9 |
Correct |
8 ms |
1512 KB |
Output is correct |
10 |
Correct |
35 ms |
31816 KB |
Output is correct |
11 |
Correct |
50 ms |
62880 KB |
Output is correct |
12 |
Correct |
11 ms |
4816 KB |
Output is correct |