#include <bits/stdc++.h>
using namespace std;
class Eertree {
public:
int sz;
string S;
int suff_max;
vector<int> len;
vector<int> occ;
vector<int> link;
vector<vector<int>> to;
Eertree() : sz(2), S(), suff_max(1), len(2), occ(2), link(2), to(2, vector<int>(26, -1)) {
len[0] = -1, link[0] = 0;
len[1] = 0, link[1] = 0;
}
int NewNode() {
len.emplace_back();
occ.emplace_back();
link.emplace_back();
to.emplace_back(vector<int>(26, -1));
return sz++;
}
int Add(char c) {
S.push_back(c);
int pos = (int) S.size() - 1;
int cur = suff_max;
while (pos - 1 - len[cur] < 0 || S[pos - 1 - len[cur]] != c) {
cur = link[cur];
}
if (to[cur][c - 'a'] != -1) {
suff_max = to[cur][c - 'a'];
occ[suff_max]++;
return 0;
}
suff_max = NewNode();
occ[suff_max] = 1;
len[suff_max] = len[cur] + 2;
to[cur][c - 'a'] = suff_max;
if (len[suff_max] == 1) {
link[suff_max] = 1;
return 1;
}
cur = link[cur];
while (pos - 1 - len[cur] < 0 || S[pos - 1 - len[cur]] != c) {
cur = link[cur];
}
link[suff_max] = to[cur][c - 'a'];
return 1;
}
long long Solve(string S) {
for (int i = 0; i < (int) S.size(); i++) {
Add(S[i]);
}
long long ans = 0;
for (int i = sz - 1; i > 1; i--) {
ans = max(ans, 1ll * len[i] * occ[i]);
occ[link[i]] += occ[i];
}
return ans;
}
};
int main() {
string S;
cin >> S;
cout << Eertree().Solve(S) << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
17 |
Correct |
1 ms |
256 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 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 |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1852 KB |
Output is correct |
2 |
Correct |
3 ms |
1852 KB |
Output is correct |
3 |
Correct |
5 ms |
1852 KB |
Output is correct |
4 |
Correct |
3 ms |
1852 KB |
Output is correct |
5 |
Correct |
3 ms |
1852 KB |
Output is correct |
6 |
Correct |
3 ms |
1852 KB |
Output is correct |
7 |
Correct |
3 ms |
1852 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
1408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
15280 KB |
Output is correct |
2 |
Correct |
27 ms |
15272 KB |
Output is correct |
3 |
Correct |
26 ms |
15280 KB |
Output is correct |
4 |
Correct |
26 ms |
15272 KB |
Output is correct |
5 |
Correct |
26 ms |
15280 KB |
Output is correct |
6 |
Correct |
20 ms |
12212 KB |
Output is correct |
7 |
Correct |
22 ms |
13104 KB |
Output is correct |
8 |
Correct |
9 ms |
896 KB |
Output is correct |
9 |
Correct |
11 ms |
4152 KB |
Output is correct |
10 |
Correct |
23 ms |
13232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
47744 KB |
Output is correct |
2 |
Correct |
77 ms |
47748 KB |
Output is correct |
3 |
Correct |
81 ms |
47616 KB |
Output is correct |
4 |
Correct |
72 ms |
47744 KB |
Output is correct |
5 |
Correct |
73 ms |
47748 KB |
Output is correct |
6 |
Correct |
73 ms |
47740 KB |
Output is correct |
7 |
Correct |
61 ms |
37632 KB |
Output is correct |
8 |
Correct |
23 ms |
2076 KB |
Output is correct |
9 |
Correct |
22 ms |
2076 KB |
Output is correct |
10 |
Correct |
60 ms |
37124 KB |
Output is correct |
11 |
Correct |
71 ms |
47616 KB |
Output is correct |
12 |
Correct |
26 ms |
5656 KB |
Output is correct |