#include <bits/stdc++.h>
using namespace std;
template<int N_, int A> struct pal_tree {
const static int N = N_ + 2;
int n, s[N], suff[N];
int k, len[N], occ[N], to[N][A], link[N];
pal_tree() : n(0), k(0) {
palindrome(0, 1);
palindrome(-1, 1);
letter(-1, 0);
}
int palindrome(int l, int suf) {
len[k] = l;
occ[k] = 0;
fill_n(to[k], A, 0);
link[k] = suf;
return k++;
}
int letter(int val, int suf) {
s[n] = val;
suff[n] = suf;
occ[suf]++;
return n++;
}
int trim(int u) {
while (s[n - 1 - len[u]] != s[n]) {
u = link[u];
}
return u;
}
void put(int c) {
s[n] = c; // don't delete :P
int u = trim(suff[n - 1]);
if (!to[u][c]) {
int v = trim(link[u]);
to[u][c] = palindrome(len[u] + 2, to[v][c]);
}
letter(c, to[u][c]);
}
int distinct() {
return k - 2;
}
void occurrences() {
for (int u = k - 1; u > 1; u--) {
occ[link[u]] += occ[u];
}
}
void clear() {
n = 1;
}
};
int main() {
pal_tree<300000, 26> t;
string s; cin >> s;
for (char c : s) t.put(c - 'a');
long long ans = 1;
t.occurrences();
for (int i = 2; i < t.k; i++) {
ans = max(ans, (long long) t.occ[i] * t.len[i]);
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
380 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
2 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1536 KB |
Output is correct |
2 |
Correct |
3 ms |
1536 KB |
Output is correct |
3 |
Correct |
3 ms |
1664 KB |
Output is correct |
4 |
Correct |
3 ms |
1536 KB |
Output is correct |
5 |
Correct |
3 ms |
1664 KB |
Output is correct |
6 |
Correct |
3 ms |
1664 KB |
Output is correct |
7 |
Correct |
4 ms |
1664 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
512 KB |
Output is correct |
10 |
Correct |
4 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
12672 KB |
Output is correct |
2 |
Correct |
15 ms |
12672 KB |
Output is correct |
3 |
Correct |
16 ms |
12672 KB |
Output is correct |
4 |
Correct |
16 ms |
12672 KB |
Output is correct |
5 |
Correct |
16 ms |
12672 KB |
Output is correct |
6 |
Correct |
15 ms |
9808 KB |
Output is correct |
7 |
Correct |
15 ms |
11000 KB |
Output is correct |
8 |
Correct |
7 ms |
1536 KB |
Output is correct |
9 |
Correct |
9 ms |
4096 KB |
Output is correct |
10 |
Correct |
15 ms |
11136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
37140 KB |
Output is correct |
2 |
Correct |
43 ms |
37524 KB |
Output is correct |
3 |
Correct |
43 ms |
37392 KB |
Output is correct |
4 |
Correct |
44 ms |
37500 KB |
Output is correct |
5 |
Correct |
51 ms |
37396 KB |
Output is correct |
6 |
Correct |
41 ms |
33812 KB |
Output is correct |
7 |
Correct |
40 ms |
31764 KB |
Output is correct |
8 |
Correct |
17 ms |
3612 KB |
Output is correct |
9 |
Correct |
16 ms |
3612 KB |
Output is correct |
10 |
Correct |
46 ms |
31252 KB |
Output is correct |
11 |
Correct |
44 ms |
37524 KB |
Output is correct |
12 |
Correct |
20 ms |
6812 KB |
Output is correct |