#include <stdio.h>
#include <string.h>
#define N 300000
#define A 26
long long max(long long a, long long b) { return a > b ? a : b; }
int tt[2 + N][A], ff[2 + N], fff[2 + N][A], len[2 + N], cnt[2 + N], _;
int node(int l) {
len[_] = l;
return _++;
}
void init() {
int a;
node(0), node(-1);
ff[0] = 1;
for (a = 0; a < A; a++)
fff[0][a] = fff[1][a] = 1;
}
int main() {
static char cc[N + 1];
int n, i, t;
long long ans;
init();
scanf("%s", cc), n = strlen(cc);
for (i = 0, t = 0; i < n; i++) {
int a = cc[i] - 'a';
if (i == len[t] || cc[i - 1 - len[t]] != cc[i])
t = fff[t][a];
if (!tt[t][a]) {
int t_ = node(len[t] + 2), f = tt[fff[t][a]][a];
tt[t][a] = t_, ff[t_] = f;
memcpy(fff[t_], fff[f], A * sizeof *fff[f]), fff[t_][cc[i - len[f]] - 'a'] = f;
}
t = tt[t][a];
cnt[t]++;
}
for (t = _ - 1; t > 1; t--)
cnt[ff[t]] += cnt[t];
ans = 0;
for (t = 2; t < _; t++)
ans = max(ans, (long long) cnt[t] * len[t]);
printf("%lld\n", ans);
return 0;
}
Compilation message
palindrome.c: In function 'main':
palindrome.c:31:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
31 | scanf("%s", cc), n = strlen(cc);
| ^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
0 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
0 ms |
364 KB |
Output is correct |
23 |
Correct |
0 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
0 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
0 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
388 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2540 KB |
Output is correct |
2 |
Correct |
2 ms |
2540 KB |
Output is correct |
3 |
Correct |
2 ms |
2540 KB |
Output is correct |
4 |
Correct |
2 ms |
2540 KB |
Output is correct |
5 |
Correct |
2 ms |
2540 KB |
Output is correct |
6 |
Correct |
2 ms |
2540 KB |
Output is correct |
7 |
Correct |
2 ms |
2540 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
1772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
21996 KB |
Output is correct |
2 |
Correct |
17 ms |
22016 KB |
Output is correct |
3 |
Correct |
18 ms |
21996 KB |
Output is correct |
4 |
Correct |
18 ms |
21996 KB |
Output is correct |
5 |
Correct |
17 ms |
21996 KB |
Output is correct |
6 |
Correct |
13 ms |
16108 KB |
Output is correct |
7 |
Correct |
14 ms |
18668 KB |
Output is correct |
8 |
Correct |
2 ms |
620 KB |
Output is correct |
9 |
Correct |
5 ms |
5484 KB |
Output is correct |
10 |
Correct |
14 ms |
18668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
65152 KB |
Output is correct |
2 |
Correct |
54 ms |
65152 KB |
Output is correct |
3 |
Correct |
51 ms |
65132 KB |
Output is correct |
4 |
Correct |
49 ms |
65132 KB |
Output is correct |
5 |
Correct |
50 ms |
65132 KB |
Output is correct |
6 |
Correct |
44 ms |
57964 KB |
Output is correct |
7 |
Correct |
41 ms |
54252 KB |
Output is correct |
8 |
Correct |
6 ms |
1004 KB |
Output is correct |
9 |
Correct |
5 ms |
876 KB |
Output is correct |
10 |
Correct |
48 ms |
53484 KB |
Output is correct |
11 |
Correct |
53 ms |
65132 KB |
Output is correct |
12 |
Correct |
9 ms |
6764 KB |
Output is correct |