#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);
ios_base :: sync_with_stdio(false);
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
77180 KB |
Output is correct |
2 |
Correct |
0 ms |
77180 KB |
Output is correct |
3 |
Correct |
0 ms |
77180 KB |
Output is correct |
4 |
Correct |
0 ms |
77180 KB |
Output is correct |
5 |
Correct |
0 ms |
77180 KB |
Output is correct |
6 |
Correct |
0 ms |
77180 KB |
Output is correct |
7 |
Correct |
0 ms |
77180 KB |
Output is correct |
8 |
Correct |
0 ms |
77180 KB |
Output is correct |
9 |
Correct |
0 ms |
77180 KB |
Output is correct |
10 |
Correct |
0 ms |
77180 KB |
Output is correct |
11 |
Correct |
0 ms |
77180 KB |
Output is correct |
12 |
Correct |
0 ms |
77180 KB |
Output is correct |
13 |
Correct |
0 ms |
77180 KB |
Output is correct |
14 |
Correct |
0 ms |
77180 KB |
Output is correct |
15 |
Correct |
0 ms |
77180 KB |
Output is correct |
16 |
Correct |
0 ms |
77180 KB |
Output is correct |
17 |
Correct |
0 ms |
77180 KB |
Output is correct |
18 |
Correct |
0 ms |
77180 KB |
Output is correct |
19 |
Correct |
0 ms |
77180 KB |
Output is correct |
20 |
Correct |
0 ms |
77180 KB |
Output is correct |
21 |
Correct |
0 ms |
77180 KB |
Output is correct |
22 |
Correct |
0 ms |
77180 KB |
Output is correct |
23 |
Correct |
0 ms |
77180 KB |
Output is correct |
24 |
Correct |
0 ms |
77180 KB |
Output is correct |
25 |
Correct |
0 ms |
77180 KB |
Output is correct |
26 |
Correct |
0 ms |
77180 KB |
Output is correct |
27 |
Correct |
0 ms |
77180 KB |
Output is correct |
28 |
Correct |
0 ms |
77180 KB |
Output is correct |
29 |
Correct |
0 ms |
77180 KB |
Output is correct |
30 |
Correct |
0 ms |
77180 KB |
Output is correct |
31 |
Correct |
0 ms |
77180 KB |
Output is correct |
32 |
Correct |
0 ms |
77180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
77180 KB |
Output is correct |
2 |
Correct |
0 ms |
77180 KB |
Output is correct |
3 |
Correct |
0 ms |
77180 KB |
Output is correct |
4 |
Correct |
0 ms |
77180 KB |
Output is correct |
5 |
Correct |
0 ms |
77180 KB |
Output is correct |
6 |
Correct |
0 ms |
77180 KB |
Output is correct |
7 |
Correct |
0 ms |
77180 KB |
Output is correct |
8 |
Correct |
0 ms |
77180 KB |
Output is correct |
9 |
Correct |
0 ms |
77180 KB |
Output is correct |
10 |
Correct |
0 ms |
77180 KB |
Output is correct |
11 |
Correct |
0 ms |
77180 KB |
Output is correct |
12 |
Correct |
0 ms |
77180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
77632 KB |
Output is correct |
2 |
Correct |
0 ms |
77500 KB |
Output is correct |
3 |
Correct |
0 ms |
77632 KB |
Output is correct |
4 |
Correct |
0 ms |
77560 KB |
Output is correct |
5 |
Correct |
3 ms |
77544 KB |
Output is correct |
6 |
Correct |
3 ms |
77472 KB |
Output is correct |
7 |
Correct |
0 ms |
77324 KB |
Output is correct |
8 |
Correct |
0 ms |
77320 KB |
Output is correct |
9 |
Correct |
0 ms |
77320 KB |
Output is correct |
10 |
Correct |
3 ms |
77356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
82212 KB |
Output is correct |
2 |
Correct |
23 ms |
80164 KB |
Output is correct |
3 |
Correct |
26 ms |
82212 KB |
Output is correct |
4 |
Correct |
36 ms |
80512 KB |
Output is correct |
5 |
Correct |
19 ms |
80756 KB |
Output is correct |
6 |
Correct |
23 ms |
79064 KB |
Output is correct |
7 |
Correct |
13 ms |
78380 KB |
Output is correct |
8 |
Correct |
3 ms |
77960 KB |
Output is correct |
9 |
Correct |
6 ms |
78576 KB |
Output is correct |
10 |
Correct |
23 ms |
80600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
92696 KB |
Output is correct |
2 |
Correct |
93 ms |
82600 KB |
Output is correct |
3 |
Correct |
76 ms |
92700 KB |
Output is correct |
4 |
Correct |
86 ms |
83740 KB |
Output is correct |
5 |
Correct |
49 ms |
90924 KB |
Output is correct |
6 |
Correct |
59 ms |
81904 KB |
Output is correct |
7 |
Correct |
63 ms |
81464 KB |
Output is correct |
8 |
Correct |
6 ms |
79788 KB |
Output is correct |
9 |
Correct |
6 ms |
79788 KB |
Output is correct |
10 |
Correct |
59 ms |
90928 KB |
Output is correct |
11 |
Correct |
109 ms |
92700 KB |
Output is correct |
12 |
Correct |
16 ms |
79916 KB |
Output is correct |