#include<iostream>
#include<string>
#include<vector>
using namespace std;
const int N = 300000 + 10;
int tree[N][26];
int idx, len[N], link[N], cnt[N], t;
string s;
long long oc[N];
void add(int p) {
while (s[p - len[t] - 1] != s[p])t = link[t];
int x = link[t];
int c = s[p] - 'a';
while (s[p - len[x] - 1] != s[p])x = link[x];
if (tree[t][c] == 0){
tree[t][c] = ++idx;
len[idx] = len[t] + 2;
link[idx] = len[idx] == 1 ? 2 : tree[x][c];
oc[idx]++;
}
else oc[tree[t][c]]++;
t = tree[t][c];
}
int main() {
len[1] = -1, link[1] = 1;
len[2] = 0, link[2] = 1;
idx = t = 2;
cin >> s;
s = '$' + s;
for (int i = 1; i < (int)s.size(); i++)add(i);
long long ans = 0;
vector<bool>fre(idx + 1, 0);
for (int i = idx; i >= 3; --i) {
oc[link[i]] += oc[i];
ans = max(ans, (1ll * len[i] * oc[i]));
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
400 KB |
Output is correct |
20 |
Correct |
0 ms |
472 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
352 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
480 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1628 KB |
Output is correct |
2 |
Correct |
1 ms |
1628 KB |
Output is correct |
3 |
Correct |
1 ms |
1628 KB |
Output is correct |
4 |
Correct |
1 ms |
1628 KB |
Output is correct |
5 |
Correct |
1 ms |
1540 KB |
Output is correct |
6 |
Correct |
1 ms |
1500 KB |
Output is correct |
7 |
Correct |
1 ms |
1628 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12376 KB |
Output is correct |
2 |
Correct |
7 ms |
12360 KB |
Output is correct |
3 |
Correct |
7 ms |
12380 KB |
Output is correct |
4 |
Correct |
12 ms |
12524 KB |
Output is correct |
5 |
Correct |
7 ms |
12380 KB |
Output is correct |
6 |
Correct |
6 ms |
9308 KB |
Output is correct |
7 |
Correct |
6 ms |
10600 KB |
Output is correct |
8 |
Correct |
3 ms |
860 KB |
Output is correct |
9 |
Correct |
4 ms |
3420 KB |
Output is correct |
10 |
Correct |
7 ms |
10584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
36304 KB |
Output is correct |
2 |
Correct |
24 ms |
36300 KB |
Output is correct |
3 |
Correct |
21 ms |
36356 KB |
Output is correct |
4 |
Correct |
20 ms |
36300 KB |
Output is correct |
5 |
Correct |
20 ms |
36188 KB |
Output is correct |
6 |
Correct |
20 ms |
32464 KB |
Output is correct |
7 |
Correct |
18 ms |
30416 KB |
Output is correct |
8 |
Correct |
8 ms |
1428 KB |
Output is correct |
9 |
Correct |
8 ms |
1268 KB |
Output is correct |
10 |
Correct |
17 ms |
29764 KB |
Output is correct |
11 |
Correct |
19 ms |
36304 KB |
Output is correct |
12 |
Correct |
8 ms |
4560 KB |
Output is correct |