#include<bits/stdc++.h>
using namespace std;
const int MXN = 300005, SGM = 26;
int n, ts, C[MXN][SGM], len[MXN], link[MXN], cnt[MXN];
char S[MXN];
inline int GetLink(int nw, int i)
{
while (S[i] != S[i - len[nw] - 1])
nw = link[nw];
return (nw);
}
inline int Add(int nw, int i)
{
int ch = S[i] - 'a';
nw = GetLink(nw, i);
if (!C[nw][ch])
{
++ ts;
len[ts] = len[nw] + 2;
link[ts] = C[GetLink(link[nw], i)][ch];
C[nw][ch] = ts;
}
return (C[nw][ch]);
}
int main()
{
scanf("%s", S);
n = strlen(S);
len[1] = -1; ts = 1;
link[0] = link[1] = 1;
int nw = 1;
for (int i = 1; i <= n; i++)
nw = Add(nw, i - 1), cnt[nw] ++;
long long Mx = 0;
for (int i = ts; i >= 0; i--)
cnt[link[i]] += cnt[i], Mx = max(Mx, 1LL * cnt[i] * len[i]);
return !printf("%lld\n", Mx);
}
Compilation message
palindrome.cpp: In function 'int main()':
palindrome.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", S);
~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
2 ms |
384 KB |
Output is correct |
32 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1536 KB |
Output is correct |
2 |
Correct |
3 ms |
1664 KB |
Output is correct |
3 |
Correct |
3 ms |
1536 KB |
Output is correct |
4 |
Correct |
3 ms |
1536 KB |
Output is correct |
5 |
Correct |
3 ms |
1536 KB |
Output is correct |
6 |
Correct |
4 ms |
1536 KB |
Output is correct |
7 |
Correct |
4 ms |
1536 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
11776 KB |
Output is correct |
2 |
Correct |
14 ms |
11916 KB |
Output is correct |
3 |
Correct |
16 ms |
11904 KB |
Output is correct |
4 |
Correct |
19 ms |
11904 KB |
Output is correct |
5 |
Correct |
22 ms |
12032 KB |
Output is correct |
6 |
Correct |
14 ms |
8832 KB |
Output is correct |
7 |
Correct |
14 ms |
10112 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
7 ms |
3200 KB |
Output is correct |
10 |
Correct |
15 ms |
10112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
34680 KB |
Output is correct |
2 |
Correct |
41 ms |
34936 KB |
Output is correct |
3 |
Correct |
39 ms |
34976 KB |
Output is correct |
4 |
Correct |
42 ms |
34936 KB |
Output is correct |
5 |
Correct |
56 ms |
34936 KB |
Output is correct |
6 |
Correct |
37 ms |
31232 KB |
Output is correct |
7 |
Correct |
38 ms |
29176 KB |
Output is correct |
8 |
Correct |
6 ms |
1152 KB |
Output is correct |
9 |
Correct |
7 ms |
1012 KB |
Output is correct |
10 |
Correct |
38 ms |
28768 KB |
Output is correct |
11 |
Correct |
42 ms |
34936 KB |
Output is correct |
12 |
Correct |
9 ms |
4248 KB |
Output is correct |