#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 |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4552 KB |
Output is correct |
15 |
Correct |
1 ms |
4552 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4440 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4548 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4552 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5212 KB |
Output is correct |
2 |
Correct |
1 ms |
5212 KB |
Output is correct |
3 |
Correct |
1 ms |
5212 KB |
Output is correct |
4 |
Correct |
1 ms |
5212 KB |
Output is correct |
5 |
Correct |
1 ms |
5212 KB |
Output is correct |
6 |
Correct |
2 ms |
5212 KB |
Output is correct |
7 |
Correct |
2 ms |
5068 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
16728 KB |
Output is correct |
2 |
Correct |
7 ms |
16724 KB |
Output is correct |
3 |
Correct |
8 ms |
16728 KB |
Output is correct |
4 |
Correct |
8 ms |
16724 KB |
Output is correct |
5 |
Correct |
9 ms |
16728 KB |
Output is correct |
6 |
Correct |
6 ms |
13912 KB |
Output is correct |
7 |
Correct |
7 ms |
15444 KB |
Output is correct |
8 |
Correct |
4 ms |
4696 KB |
Output is correct |
9 |
Correct |
4 ms |
8792 KB |
Output is correct |
10 |
Correct |
7 ms |
15192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
37316 KB |
Output is correct |
2 |
Correct |
19 ms |
37320 KB |
Output is correct |
3 |
Correct |
22 ms |
37324 KB |
Output is correct |
4 |
Correct |
21 ms |
37328 KB |
Output is correct |
5 |
Correct |
22 ms |
37472 KB |
Output is correct |
6 |
Correct |
23 ms |
34000 KB |
Output is correct |
7 |
Correct |
18 ms |
32208 KB |
Output is correct |
8 |
Correct |
9 ms |
5368 KB |
Output is correct |
9 |
Correct |
8 ms |
5488 KB |
Output is correct |
10 |
Correct |
21 ms |
31744 KB |
Output is correct |
11 |
Correct |
19 ms |
37580 KB |
Output is correct |
12 |
Correct |
10 ms |
9936 KB |
Output is correct |