#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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;
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;}
};
pal_tree<300000,26> t;
int main() {
string s;
cin >> s;
for(char c : s) t.put(c - 'a');
ll 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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
400 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
372 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
300 KB |
Output is correct |
28 |
Correct |
2 ms |
380 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1784 KB |
Output is correct |
2 |
Correct |
4 ms |
1656 KB |
Output is correct |
3 |
Correct |
4 ms |
1528 KB |
Output is correct |
4 |
Correct |
5 ms |
1528 KB |
Output is correct |
5 |
Correct |
4 ms |
1660 KB |
Output is correct |
6 |
Correct |
4 ms |
1528 KB |
Output is correct |
7 |
Correct |
4 ms |
1528 KB |
Output is correct |
8 |
Correct |
3 ms |
532 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
4 ms |
1272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
12792 KB |
Output is correct |
2 |
Correct |
20 ms |
12792 KB |
Output is correct |
3 |
Correct |
20 ms |
12792 KB |
Output is correct |
4 |
Correct |
20 ms |
12792 KB |
Output is correct |
5 |
Correct |
21 ms |
12792 KB |
Output is correct |
6 |
Correct |
18 ms |
9720 KB |
Output is correct |
7 |
Correct |
20 ms |
11104 KB |
Output is correct |
8 |
Correct |
11 ms |
1528 KB |
Output is correct |
9 |
Correct |
13 ms |
4088 KB |
Output is correct |
10 |
Correct |
19 ms |
11128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
37524 KB |
Output is correct |
2 |
Correct |
58 ms |
37524 KB |
Output is correct |
3 |
Correct |
56 ms |
37396 KB |
Output is correct |
4 |
Correct |
57 ms |
37396 KB |
Output is correct |
5 |
Correct |
63 ms |
37396 KB |
Output is correct |
6 |
Correct |
54 ms |
33684 KB |
Output is correct |
7 |
Correct |
54 ms |
31760 KB |
Output is correct |
8 |
Correct |
26 ms |
3604 KB |
Output is correct |
9 |
Correct |
26 ms |
3604 KB |
Output is correct |
10 |
Correct |
57 ms |
31252 KB |
Output is correct |
11 |
Correct |
57 ms |
37396 KB |
Output is correct |
12 |
Correct |
28 ms |
6676 KB |
Output is correct |