#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;
using ll=long long;
#define pb push_back
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=1;i<=n;++i)
const int maxn = int(6e5) + 10;
char s[maxn];
int n;
int nxt[maxn][27];
int fail[maxn];
int cnt[maxn], dep[maxn], par[maxn];
int myv[maxn];
int rad[maxn], lng[maxn];
int nn, root;
int G(int v, int i) {
if (!nxt[v][i]) {
nxt[v][i] = ++nn;
dep[nn] = dep[v] + 1;
par[nn] = v;
}
return nxt[v][i];
}
int main() {
scanf("%s", s);
n = strlen(s);
{ // inflate
for (int i=n-1; 0<=i; --i) s[2*i+1] = s[i];
for (int i=0; i<=n; ++i) s[2*i] = '{';
n = 2*n+1;
}
root = ++nn; fail[root] = root;
fail[myv[0] = G(root, s[0]-'a')] = root;
for (int i=1; i<n; ++i) {
int v = myv[i-1];
while (v != root) {
int r = dep[v], h = 2*(i-r)-i;
if (h >= 0 && s[i] == s[h]) break;
v = fail[v];
}
int h = 2*(i-dep[v])-i;
if (h >= 0 && s[h] == s[i]) {
if (!nxt[v][s[i]-'a']) {
int f = fail[v];
for(; f!=root; f=fail[f]) {
if (s[2*(i-dep[f])-i] == s[i]) {
break;
}
}
if (nxt[f][s[i]-'a'])
f = G(f, s[i]-'a');
fail[G(v, s[i]-'a')] = f;
}
myv[i] = v = G(v, s[i]-'a');
} else {
v = myv[i] = G(root, s[i]-'a');
fail[v] = root;
}
}
for(int i=0; i<n; ++i) ++cnt[myv[i]];
for(int i=nn; 1<i; --i) cnt[fail[i]] += cnt[i];
ll ans = 0;
for (int i=1; i<=nn; ++i) ans = max(ans, (dep[i]-1)*1ll*cnt[i]);
printf("%lld\n", ans);
return 0;
}
Compilation message
palindrome.cpp: In function 'int main()':
palindrome.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
35 | scanf("%s", s);
| ~~~~~^~~~~~~~~
# |
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 |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 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 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
0 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
0 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
0 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
640 KB |
Output is correct |
2 |
Correct |
1 ms |
672 KB |
Output is correct |
3 |
Correct |
1 ms |
640 KB |
Output is correct |
4 |
Correct |
1 ms |
640 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
640 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2944 KB |
Output is correct |
2 |
Correct |
3 ms |
2944 KB |
Output is correct |
3 |
Correct |
3 ms |
2944 KB |
Output is correct |
4 |
Correct |
2 ms |
2944 KB |
Output is correct |
5 |
Correct |
3 ms |
2944 KB |
Output is correct |
6 |
Correct |
3 ms |
2944 KB |
Output is correct |
7 |
Correct |
3 ms |
2944 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
2176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
25728 KB |
Output is correct |
2 |
Correct |
22 ms |
25728 KB |
Output is correct |
3 |
Correct |
22 ms |
25728 KB |
Output is correct |
4 |
Correct |
22 ms |
25728 KB |
Output is correct |
5 |
Correct |
23 ms |
25720 KB |
Output is correct |
6 |
Correct |
17 ms |
19072 KB |
Output is correct |
7 |
Correct |
19 ms |
21880 KB |
Output is correct |
8 |
Correct |
4 ms |
1664 KB |
Output is correct |
9 |
Correct |
8 ms |
7040 KB |
Output is correct |
10 |
Correct |
20 ms |
22016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
76280 KB |
Output is correct |
2 |
Correct |
63 ms |
76264 KB |
Output is correct |
3 |
Correct |
63 ms |
76280 KB |
Output is correct |
4 |
Correct |
62 ms |
76408 KB |
Output is correct |
5 |
Correct |
65 ms |
76280 KB |
Output is correct |
6 |
Correct |
56 ms |
68216 KB |
Output is correct |
7 |
Correct |
55 ms |
64124 KB |
Output is correct |
8 |
Correct |
12 ms |
3968 KB |
Output is correct |
9 |
Correct |
12 ms |
3968 KB |
Output is correct |
10 |
Correct |
58 ms |
63096 KB |
Output is correct |
11 |
Correct |
62 ms |
76280 KB |
Output is correct |
12 |
Correct |
17 ms |
10496 KB |
Output is correct |