#include <iostream>
#define int long long
using namespace std;
const int MAX_N = 3 * 1e5;
const int SIGMA = 26;
string s;
struct Node {
int next[SIGMA];
int sufflink;
int len;
int num;
int occ = 0;
};
Node tree[MAX_N + 3];
int cnt = 2, suffix = 2;
void addletter(int pos) {
int let = s[pos] - 'a';
int cur = suffix, curlen = 0;
while (true) {
curlen = tree[cur].len;
if (pos - curlen - 1 >= 0 && s[pos - curlen - 1] == s[pos]) {
break;
}
cur = tree[cur].sufflink;
}
if (tree[cur].next[let]) {
suffix = tree[cur].next[let];
tree[suffix].occ++;
return;
}
cnt++;
suffix = cnt;
tree[cnt].len = tree[cur].len + 2;
tree[cnt].occ++;
tree[cur].next[let] = cnt;
if (tree[cnt].len == 1) {
tree[cnt].sufflink = 2;
tree[cnt].num = 1;
return;
}
while (true) {
cur = tree[cur].sufflink;
curlen = tree[cur].len;
if (pos - curlen - 1 >= 0 && s[pos - curlen - 1] == s[pos]) {
tree[cnt].sufflink = tree[cur].next[let];
break;
}
}
tree[cnt].num = tree[tree[cnt].sufflink].num + 1;
}
void init() {
tree[1].len = -1;
tree[1].sufflink = 1;
tree[2].len = 0;
tree[2].sufflink = 1;
}
signed main() {
cin >> s;
int n = s.size();
init();
for (int i = 0; i < n; i++) {
addletter(i);
}
int answer = 0;
for (int i = cnt; i >= 1; i--) {
tree[tree[i].sufflink].occ += tree[i].occ;
}
for (int i = 1; i <= cnt; i++) {
answer = max(answer, tree[i].occ * tree[i].len);
}
cout << answer;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
70752 KB |
Output is correct |
2 |
Correct |
31 ms |
70660 KB |
Output is correct |
3 |
Correct |
33 ms |
70656 KB |
Output is correct |
4 |
Correct |
27 ms |
70740 KB |
Output is correct |
5 |
Correct |
27 ms |
70716 KB |
Output is correct |
6 |
Correct |
27 ms |
70744 KB |
Output is correct |
7 |
Correct |
28 ms |
70752 KB |
Output is correct |
8 |
Correct |
27 ms |
70712 KB |
Output is correct |
9 |
Correct |
30 ms |
70684 KB |
Output is correct |
10 |
Correct |
28 ms |
70740 KB |
Output is correct |
11 |
Correct |
29 ms |
70636 KB |
Output is correct |
12 |
Correct |
29 ms |
70732 KB |
Output is correct |
13 |
Correct |
27 ms |
70628 KB |
Output is correct |
14 |
Correct |
27 ms |
70724 KB |
Output is correct |
15 |
Correct |
28 ms |
70732 KB |
Output is correct |
16 |
Correct |
27 ms |
70756 KB |
Output is correct |
17 |
Correct |
27 ms |
70680 KB |
Output is correct |
18 |
Correct |
32 ms |
70740 KB |
Output is correct |
19 |
Correct |
31 ms |
70728 KB |
Output is correct |
20 |
Correct |
29 ms |
70752 KB |
Output is correct |
21 |
Correct |
28 ms |
70676 KB |
Output is correct |
22 |
Correct |
29 ms |
70704 KB |
Output is correct |
23 |
Correct |
27 ms |
70732 KB |
Output is correct |
24 |
Correct |
28 ms |
70740 KB |
Output is correct |
25 |
Correct |
28 ms |
70740 KB |
Output is correct |
26 |
Correct |
30 ms |
70740 KB |
Output is correct |
27 |
Correct |
28 ms |
70664 KB |
Output is correct |
28 |
Correct |
28 ms |
70680 KB |
Output is correct |
29 |
Correct |
29 ms |
70732 KB |
Output is correct |
30 |
Correct |
30 ms |
70732 KB |
Output is correct |
31 |
Correct |
27 ms |
70740 KB |
Output is correct |
32 |
Correct |
27 ms |
70740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
70704 KB |
Output is correct |
2 |
Correct |
28 ms |
70736 KB |
Output is correct |
3 |
Correct |
32 ms |
70628 KB |
Output is correct |
4 |
Correct |
28 ms |
70736 KB |
Output is correct |
5 |
Correct |
28 ms |
70756 KB |
Output is correct |
6 |
Correct |
29 ms |
70736 KB |
Output is correct |
7 |
Correct |
28 ms |
70740 KB |
Output is correct |
8 |
Correct |
31 ms |
70752 KB |
Output is correct |
9 |
Correct |
28 ms |
70744 KB |
Output is correct |
10 |
Correct |
27 ms |
70736 KB |
Output is correct |
11 |
Correct |
29 ms |
70716 KB |
Output is correct |
12 |
Correct |
31 ms |
70732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
70708 KB |
Output is correct |
2 |
Correct |
28 ms |
70684 KB |
Output is correct |
3 |
Correct |
32 ms |
70740 KB |
Output is correct |
4 |
Correct |
27 ms |
70740 KB |
Output is correct |
5 |
Correct |
29 ms |
70748 KB |
Output is correct |
6 |
Correct |
28 ms |
70792 KB |
Output is correct |
7 |
Correct |
28 ms |
70740 KB |
Output is correct |
8 |
Correct |
29 ms |
70768 KB |
Output is correct |
9 |
Correct |
27 ms |
70760 KB |
Output is correct |
10 |
Correct |
28 ms |
70760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
70960 KB |
Output is correct |
2 |
Correct |
42 ms |
71020 KB |
Output is correct |
3 |
Correct |
34 ms |
70992 KB |
Output is correct |
4 |
Correct |
36 ms |
70988 KB |
Output is correct |
5 |
Correct |
35 ms |
71004 KB |
Output is correct |
6 |
Correct |
38 ms |
70996 KB |
Output is correct |
7 |
Correct |
36 ms |
70948 KB |
Output is correct |
8 |
Correct |
34 ms |
71004 KB |
Output is correct |
9 |
Correct |
31 ms |
70988 KB |
Output is correct |
10 |
Correct |
35 ms |
71056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
71544 KB |
Output is correct |
2 |
Correct |
51 ms |
71624 KB |
Output is correct |
3 |
Correct |
46 ms |
71532 KB |
Output is correct |
4 |
Correct |
48 ms |
71556 KB |
Output is correct |
5 |
Correct |
54 ms |
71576 KB |
Output is correct |
6 |
Correct |
49 ms |
71652 KB |
Output is correct |
7 |
Correct |
49 ms |
71536 KB |
Output is correct |
8 |
Correct |
41 ms |
71608 KB |
Output is correct |
9 |
Correct |
38 ms |
71644 KB |
Output is correct |
10 |
Correct |
45 ms |
71632 KB |
Output is correct |
11 |
Correct |
47 ms |
71644 KB |
Output is correct |
12 |
Correct |
40 ms |
71656 KB |
Output is correct |