#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
const int MAXN = 300007;
int link[MAXN], nxt[MAXN][26], len[MAXN], val[MAXN];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
string S;
cin >> S;
len[1] = -1, len[2] = 0;
link[2] = 1;
int u = 2, cnt = 2;
int N = ((int) S.size());
S = "-" + S;
for (int i = 1; i <= N; ++i) {
int c = (int) (S[i] - 'a');
while (S[i] != S[i - len[u] - 1]) u = link[u];
if (!nxt[u][c]) {
nxt[u][c] = ++cnt;
// cout << u << " -> " << nxt[u][c] << ": " << char(c + 'a') << endl;
len[nxt[u][c]] = len[u] + 2;
int v;
for (v = link[u]; v && !nxt[v][c]; v = link[v]);
if (v == 0) link[nxt[u][c]] = 2;
else link[nxt[u][c]] = nxt[v][c];
}
u = nxt[u][c];
++val[u];
}
int64_t ans = 0;
for (int u = cnt; u > 2; --u) {
if (link[u]) val[link[u]] += val[u];
ans = max(ans, (int64_t) val[u] * len[u]);
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
0 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1536 KB |
Output is correct |
2 |
Correct |
1 ms |
1536 KB |
Output is correct |
3 |
Correct |
1 ms |
1536 KB |
Output is correct |
4 |
Correct |
2 ms |
1536 KB |
Output is correct |
5 |
Correct |
1 ms |
1536 KB |
Output is correct |
6 |
Correct |
1 ms |
1556 KB |
Output is correct |
7 |
Correct |
1 ms |
1536 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Incorrect |
1 ms |
1152 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
12020 KB |
Output is correct |
2 |
Correct |
10 ms |
12028 KB |
Output is correct |
3 |
Correct |
9 ms |
12060 KB |
Output is correct |
4 |
Correct |
10 ms |
12028 KB |
Output is correct |
5 |
Correct |
10 ms |
12028 KB |
Output is correct |
6 |
Correct |
7 ms |
8956 KB |
Output is correct |
7 |
Correct |
8 ms |
10236 KB |
Output is correct |
8 |
Correct |
2 ms |
764 KB |
Output is correct |
9 |
Correct |
4 ms |
3324 KB |
Output is correct |
10 |
Incorrect |
7 ms |
9724 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
35164 KB |
Output is correct |
2 |
Correct |
26 ms |
35140 KB |
Output is correct |
3 |
Correct |
27 ms |
35160 KB |
Output is correct |
4 |
Correct |
28 ms |
35168 KB |
Output is correct |
5 |
Correct |
27 ms |
35160 KB |
Output is correct |
6 |
Correct |
24 ms |
31320 KB |
Output is correct |
7 |
Correct |
24 ms |
29400 KB |
Output is correct |
8 |
Correct |
6 ms |
1416 KB |
Output is correct |
9 |
Correct |
5 ms |
1416 KB |
Output is correct |
10 |
Incorrect |
22 ms |
28384 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |