#include <bits/stdc++.h>
using namespace std;
const int NMAX = 2 * 300000 + 5;
inline int toInt(char ch) {
if (ch == '#')
return 0;
else
return ch - 'a' + 1;
}
string str;
int nodes;
int alf[NMAX][27];
int h[NMAX];
int father[NMAX];
int ext[NMAX];
int whichNode[NMAX];
int cnt[NMAX];
long long int ans = 1;
void dfs(int node, int realH) {
for (int i = 0; i < 27; ++ i)
if (alf[node][i]) {
dfs(alf[node][i], realH + (i > 0) * (1 + (node > 1)));
cnt[node] += cnt[alf[node][i]];
}
ans = max(ans, 1LL * realH * cnt[node]);
}
int main()
{
//freopen("data.in", "r", stdin);
cin >> str;
string str2 = "#";
for (auto it: str) {
str2 += it;
str2 += '#';
}
str = str2;
str = " " + str;
int N = str.size() - 1;
++ nodes;
int center = 0;
for (int i = 1; i <= N; ++ i) {
int node = 1;
int l = 0;
if (center + ext[center] - 1 >= i) {
node = whichNode[2 * center - i];
l = h[node];
while (l > center + ext[center] - i) {
node = father[node];
l --;
}
}
while (i - l >= 1 && i + l <= N && str[i - l] == str[i + l]) {
if (!alf[node][toInt(str[i - l])]) {
alf[node][toInt(str[i - l])] = ++ nodes;
h[nodes] = 1 + h[node];
father[nodes] = node;
}
node = alf[node][toInt(str[i - l])];
++ l;
}
ext[i] = l;
whichNode[i] = node;
++ cnt[node];
if (i + ext[i] > center + ext[center])
center = i;
}
dfs(1, 0);
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
77020 KB |
Output is correct |
2 |
Correct |
0 ms |
77020 KB |
Output is correct |
3 |
Correct |
0 ms |
77020 KB |
Output is correct |
4 |
Correct |
0 ms |
77020 KB |
Output is correct |
5 |
Correct |
0 ms |
77020 KB |
Output is correct |
6 |
Correct |
0 ms |
77020 KB |
Output is correct |
7 |
Correct |
0 ms |
77020 KB |
Output is correct |
8 |
Correct |
0 ms |
77020 KB |
Output is correct |
9 |
Correct |
0 ms |
77020 KB |
Output is correct |
10 |
Correct |
0 ms |
77020 KB |
Output is correct |
11 |
Correct |
0 ms |
77020 KB |
Output is correct |
12 |
Correct |
0 ms |
77020 KB |
Output is correct |
13 |
Correct |
0 ms |
77020 KB |
Output is correct |
14 |
Correct |
0 ms |
77020 KB |
Output is correct |
15 |
Correct |
0 ms |
77020 KB |
Output is correct |
16 |
Correct |
0 ms |
77020 KB |
Output is correct |
17 |
Correct |
0 ms |
77020 KB |
Output is correct |
18 |
Correct |
0 ms |
77020 KB |
Output is correct |
19 |
Correct |
0 ms |
77020 KB |
Output is correct |
20 |
Correct |
0 ms |
77020 KB |
Output is correct |
21 |
Correct |
0 ms |
77020 KB |
Output is correct |
22 |
Correct |
0 ms |
77020 KB |
Output is correct |
23 |
Correct |
0 ms |
77020 KB |
Output is correct |
24 |
Correct |
0 ms |
77020 KB |
Output is correct |
25 |
Correct |
0 ms |
77020 KB |
Output is correct |
26 |
Correct |
0 ms |
77020 KB |
Output is correct |
27 |
Correct |
0 ms |
77020 KB |
Output is correct |
28 |
Correct |
0 ms |
77020 KB |
Output is correct |
29 |
Correct |
0 ms |
77020 KB |
Output is correct |
30 |
Correct |
0 ms |
77020 KB |
Output is correct |
31 |
Correct |
0 ms |
77020 KB |
Output is correct |
32 |
Correct |
0 ms |
77020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
77020 KB |
Output is correct |
2 |
Correct |
0 ms |
77020 KB |
Output is correct |
3 |
Correct |
0 ms |
77020 KB |
Output is correct |
4 |
Correct |
0 ms |
77020 KB |
Output is correct |
5 |
Correct |
0 ms |
77020 KB |
Output is correct |
6 |
Correct |
0 ms |
77020 KB |
Output is correct |
7 |
Correct |
0 ms |
77020 KB |
Output is correct |
8 |
Correct |
0 ms |
77020 KB |
Output is correct |
9 |
Correct |
0 ms |
77020 KB |
Output is correct |
10 |
Correct |
0 ms |
77020 KB |
Output is correct |
11 |
Correct |
0 ms |
77020 KB |
Output is correct |
12 |
Correct |
0 ms |
77020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
77512 KB |
Output is correct |
2 |
Correct |
0 ms |
77384 KB |
Output is correct |
3 |
Correct |
3 ms |
77520 KB |
Output is correct |
4 |
Correct |
3 ms |
77444 KB |
Output is correct |
5 |
Correct |
3 ms |
77432 KB |
Output is correct |
6 |
Correct |
3 ms |
77364 KB |
Output is correct |
7 |
Correct |
0 ms |
77208 KB |
Output is correct |
8 |
Correct |
0 ms |
77172 KB |
Output is correct |
9 |
Correct |
0 ms |
77172 KB |
Output is correct |
10 |
Correct |
0 ms |
77236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
82096 KB |
Output is correct |
2 |
Correct |
26 ms |
80052 KB |
Output is correct |
3 |
Correct |
23 ms |
82096 KB |
Output is correct |
4 |
Correct |
23 ms |
80400 KB |
Output is correct |
5 |
Correct |
16 ms |
80644 KB |
Output is correct |
6 |
Correct |
16 ms |
78948 KB |
Output is correct |
7 |
Correct |
16 ms |
78264 KB |
Output is correct |
8 |
Correct |
0 ms |
77824 KB |
Output is correct |
9 |
Correct |
6 ms |
78460 KB |
Output is correct |
10 |
Correct |
23 ms |
80484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
129 ms |
92588 KB |
Output is correct |
2 |
Correct |
93 ms |
82488 KB |
Output is correct |
3 |
Correct |
103 ms |
92584 KB |
Output is correct |
4 |
Correct |
93 ms |
83624 KB |
Output is correct |
5 |
Correct |
69 ms |
90816 KB |
Output is correct |
6 |
Correct |
69 ms |
81784 KB |
Output is correct |
7 |
Correct |
73 ms |
81344 KB |
Output is correct |
8 |
Correct |
23 ms |
79612 KB |
Output is correct |
9 |
Correct |
26 ms |
79612 KB |
Output is correct |
10 |
Correct |
73 ms |
90808 KB |
Output is correct |
11 |
Correct |
119 ms |
92580 KB |
Output is correct |
12 |
Correct |
23 ms |
79800 KB |
Output is correct |