#include <bits/stdc++.h>
using namespace std;
const int A = 26;
const int N = 300010;
char s[N]; long long ans;
int last, ptr, nxt[N][A], link[N], len[N], occ[N];
void feed (int at) {
while (s[at - len[last] - 1] != s[at]) last = link[last];
int ch = s[at] - 'a', temp = link[last];
while (s[at - len[temp] - 1] != s[at]) temp = link[temp];
if (!nxt[last][ch]) {
nxt[last][ch] = ++ptr, len[ptr] = len[last] + 2;
link[ptr] = len[ptr] == 1 ? 2 : nxt[temp][ch];
}
last = nxt[last][ch], ++occ[last];
}
int main() {
len[1] = -1, len[2] = 0, link[1] = link[2] = 1, last = ptr = 2;
scanf("%s", s + 1);
for (int i = 1, n = strlen(s + 1); i <= n; ++i) feed(i);
for (int i = ptr; i > 2; --i) ans = max(ans, len[i] * 1LL * occ[i]), occ[link[i]] += occ[i];
printf("%lld\n", ans);
return 0;
}
Compilation message
palindrome.cpp: In function 'int main()':
palindrome.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", s + 1);
~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
456 KB |
Output is correct |
3 |
Correct |
2 ms |
456 KB |
Output is correct |
4 |
Correct |
2 ms |
456 KB |
Output is correct |
5 |
Correct |
2 ms |
456 KB |
Output is correct |
6 |
Correct |
2 ms |
476 KB |
Output is correct |
7 |
Correct |
2 ms |
476 KB |
Output is correct |
8 |
Correct |
2 ms |
488 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
680 KB |
Output is correct |
11 |
Correct |
2 ms |
696 KB |
Output is correct |
12 |
Correct |
2 ms |
696 KB |
Output is correct |
13 |
Correct |
2 ms |
696 KB |
Output is correct |
14 |
Correct |
2 ms |
696 KB |
Output is correct |
15 |
Correct |
2 ms |
696 KB |
Output is correct |
16 |
Correct |
2 ms |
696 KB |
Output is correct |
17 |
Correct |
2 ms |
696 KB |
Output is correct |
18 |
Correct |
2 ms |
696 KB |
Output is correct |
19 |
Correct |
2 ms |
788 KB |
Output is correct |
20 |
Correct |
2 ms |
788 KB |
Output is correct |
21 |
Correct |
2 ms |
788 KB |
Output is correct |
22 |
Correct |
2 ms |
788 KB |
Output is correct |
23 |
Correct |
2 ms |
788 KB |
Output is correct |
24 |
Correct |
2 ms |
788 KB |
Output is correct |
25 |
Correct |
2 ms |
788 KB |
Output is correct |
26 |
Correct |
2 ms |
788 KB |
Output is correct |
27 |
Correct |
2 ms |
812 KB |
Output is correct |
28 |
Correct |
2 ms |
816 KB |
Output is correct |
29 |
Correct |
2 ms |
816 KB |
Output is correct |
30 |
Correct |
2 ms |
816 KB |
Output is correct |
31 |
Correct |
2 ms |
816 KB |
Output is correct |
32 |
Correct |
2 ms |
816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
864 KB |
Output is correct |
2 |
Correct |
2 ms |
884 KB |
Output is correct |
3 |
Correct |
2 ms |
884 KB |
Output is correct |
4 |
Correct |
2 ms |
888 KB |
Output is correct |
5 |
Correct |
2 ms |
896 KB |
Output is correct |
6 |
Correct |
2 ms |
896 KB |
Output is correct |
7 |
Correct |
2 ms |
900 KB |
Output is correct |
8 |
Correct |
2 ms |
904 KB |
Output is correct |
9 |
Correct |
2 ms |
904 KB |
Output is correct |
10 |
Correct |
2 ms |
904 KB |
Output is correct |
11 |
Correct |
2 ms |
904 KB |
Output is correct |
12 |
Correct |
2 ms |
904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1964 KB |
Output is correct |
2 |
Correct |
3 ms |
1976 KB |
Output is correct |
3 |
Correct |
3 ms |
1988 KB |
Output is correct |
4 |
Correct |
3 ms |
2000 KB |
Output is correct |
5 |
Correct |
3 ms |
2112 KB |
Output is correct |
6 |
Correct |
3 ms |
2112 KB |
Output is correct |
7 |
Correct |
4 ms |
2136 KB |
Output is correct |
8 |
Correct |
2 ms |
2136 KB |
Output is correct |
9 |
Correct |
2 ms |
2136 KB |
Output is correct |
10 |
Correct |
3 ms |
2136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
12452 KB |
Output is correct |
2 |
Correct |
14 ms |
12552 KB |
Output is correct |
3 |
Correct |
14 ms |
12652 KB |
Output is correct |
4 |
Correct |
15 ms |
12752 KB |
Output is correct |
5 |
Correct |
16 ms |
12852 KB |
Output is correct |
6 |
Correct |
13 ms |
12852 KB |
Output is correct |
7 |
Correct |
12 ms |
12852 KB |
Output is correct |
8 |
Correct |
4 ms |
12852 KB |
Output is correct |
9 |
Correct |
6 ms |
12852 KB |
Output is correct |
10 |
Correct |
12 ms |
12852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
36492 KB |
Output is correct |
2 |
Correct |
40 ms |
36788 KB |
Output is correct |
3 |
Correct |
36 ms |
37104 KB |
Output is correct |
4 |
Correct |
36 ms |
37380 KB |
Output is correct |
5 |
Correct |
48 ms |
37640 KB |
Output is correct |
6 |
Correct |
37 ms |
37640 KB |
Output is correct |
7 |
Correct |
35 ms |
37640 KB |
Output is correct |
8 |
Correct |
6 ms |
37640 KB |
Output is correct |
9 |
Correct |
6 ms |
37640 KB |
Output is correct |
10 |
Correct |
39 ms |
37640 KB |
Output is correct |
11 |
Correct |
39 ms |
37640 KB |
Output is correct |
12 |
Correct |
9 ms |
37640 KB |
Output is correct |