//#include "shoes.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e5+10;
int tree[N][26], idx, len[N], link[N], t, n, occ[N];
string k;
char s[N];
void init() {
len[1] = -1, len[2] = 0;
link[1] = 1, link[2] = 1;
idx = t = 2;
}
void extend(int p) {
while(s[p - len[t] - 1] != s[p]) t = link[t]; //WoW
int x = link[t], c = s[p]-'a';
if(!tree[t][c]) {
while(s[p - len[x] - 1] != s[p]) x = link[x];
tree[t][c] = ++idx;
len[idx] = len[t] + 2;
link[idx] = len[idx] == 1 ? 2 : tree[x][c];
}
t = tree[t][c];
//printf("%d %d\n", p, t);
occ[t]++;
}
int main() {
cin >> k;
init();
n = k.size();
for(int i = 0; i < n; i++) s[i+1] = k[i];
for(int i = 1; i <= n; i++) extend(i);
for(int i = idx; i > 2; i--) {
occ[link[i]] += occ[i];
}
ll ans = 0;
for(int i = 2; i <= idx; i++) {
ans = max(ans, (ll)len[i] * occ[i]);
}
printf("%lld\n", ans);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
0 ms |
384 KB |
Output is correct |
24 |
Correct |
0 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
0 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
0 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1536 KB |
Output is correct |
2 |
Correct |
2 ms |
1536 KB |
Output is correct |
3 |
Correct |
2 ms |
1536 KB |
Output is correct |
4 |
Correct |
2 ms |
1536 KB |
Output is correct |
5 |
Correct |
2 ms |
1536 KB |
Output is correct |
6 |
Correct |
2 ms |
1536 KB |
Output is correct |
7 |
Correct |
2 ms |
1536 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
1184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
12032 KB |
Output is correct |
2 |
Correct |
15 ms |
12032 KB |
Output is correct |
3 |
Correct |
15 ms |
12032 KB |
Output is correct |
4 |
Correct |
18 ms |
12032 KB |
Output is correct |
5 |
Correct |
15 ms |
12032 KB |
Output is correct |
6 |
Correct |
13 ms |
8960 KB |
Output is correct |
7 |
Correct |
14 ms |
10240 KB |
Output is correct |
8 |
Correct |
7 ms |
768 KB |
Output is correct |
9 |
Correct |
9 ms |
3328 KB |
Output is correct |
10 |
Correct |
16 ms |
10368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
35096 KB |
Output is correct |
2 |
Correct |
44 ms |
35344 KB |
Output is correct |
3 |
Correct |
44 ms |
35348 KB |
Output is correct |
4 |
Correct |
45 ms |
35348 KB |
Output is correct |
5 |
Correct |
45 ms |
35348 KB |
Output is correct |
6 |
Correct |
41 ms |
31636 KB |
Output is correct |
7 |
Correct |
42 ms |
29588 KB |
Output is correct |
8 |
Correct |
20 ms |
1564 KB |
Output is correct |
9 |
Correct |
20 ms |
1588 KB |
Output is correct |
10 |
Correct |
40 ms |
29204 KB |
Output is correct |
11 |
Correct |
42 ms |
35476 KB |
Output is correct |
12 |
Correct |
22 ms |
4636 KB |
Output is correct |