#include <cstdio>
#include <cstring>
#include <cassert>
#include <vector>
template<typename T> bool ckmax(T& a, const T& b) {return a<b?a=b,1:0;}
const int MN = 3e5+10;
const int MK = 26;
typedef long long ll;
int N, c[MN][MK], l[MN], d[MN], p, X=1, v[MN];
ll f;
std::vector<int> dw[MN];
char s[MN];
void dfs(int n)
{
for(auto x:dw[n])
dfs(x), v[n]+=v[x];
ckmax(f, (ll)v[n]*d[n]);
}
int main()
{
scanf(" %s", s+1);
for(N=1;s[N];++N)s[N]-='a';
s[0]=-1, s[N--]=-2;
memset(c, -1, sizeof c);
d[0]=l[0]=-1, d[1]=l[1]=0;
dw[0].push_back(1);
for(int i=1;i<=N;++i)
{
for(;s[i]!=s[i-d[p]-1];)p=l[p];
if(!~c[p][s[i]])
{
c[p][s[i]]=++X;
d[X]=d[p]+2, l[X]=l[p];
p=X;
for(;~l[p] && s[i]!=s[i-d[l[p]]-1];l[p]=l[l[p]]);
if(~l[p] && s[i]==s[i-d[l[p]]-1])
l[p]=c[l[p]][s[i]];
else
l[p]=1;
assert(~l[p]);
dw[l[p]].push_back(p);
}
else
p=c[p][s[i]];
++v[p];
}
dfs(0);
printf("%lld\n", f);
return 0;
}
Compilation message
palindrome.cpp: In function 'int main()':
palindrome.cpp:34:17: warning: array subscript has type 'char' [-Wchar-subscripts]
if(!~c[p][s[i]])
^
palindrome.cpp:36:13: warning: array subscript has type 'char' [-Wchar-subscripts]
c[p][s[i]]=++X;
^
palindrome.cpp:41:22: warning: array subscript has type 'char' [-Wchar-subscripts]
l[p]=c[l[p]][s[i]];
^
palindrome.cpp:48:15: warning: array subscript has type 'char' [-Wchar-subscripts]
p=c[p][s[i]];
^
palindrome.cpp:25:7: 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 |
20 ms |
37880 KB |
Output is correct |
2 |
Correct |
18 ms |
37888 KB |
Output is correct |
3 |
Correct |
20 ms |
37888 KB |
Output is correct |
4 |
Correct |
20 ms |
37888 KB |
Output is correct |
5 |
Correct |
18 ms |
37888 KB |
Output is correct |
6 |
Correct |
24 ms |
37888 KB |
Output is correct |
7 |
Correct |
18 ms |
37888 KB |
Output is correct |
8 |
Correct |
20 ms |
37888 KB |
Output is correct |
9 |
Correct |
18 ms |
37888 KB |
Output is correct |
10 |
Correct |
18 ms |
37888 KB |
Output is correct |
11 |
Correct |
18 ms |
37888 KB |
Output is correct |
12 |
Correct |
21 ms |
37888 KB |
Output is correct |
13 |
Correct |
19 ms |
37888 KB |
Output is correct |
14 |
Correct |
20 ms |
37888 KB |
Output is correct |
15 |
Correct |
19 ms |
37888 KB |
Output is correct |
16 |
Correct |
20 ms |
37888 KB |
Output is correct |
17 |
Correct |
18 ms |
37888 KB |
Output is correct |
18 |
Correct |
20 ms |
37880 KB |
Output is correct |
19 |
Correct |
18 ms |
37888 KB |
Output is correct |
20 |
Correct |
19 ms |
37888 KB |
Output is correct |
21 |
Correct |
18 ms |
37888 KB |
Output is correct |
22 |
Correct |
18 ms |
37888 KB |
Output is correct |
23 |
Correct |
18 ms |
37888 KB |
Output is correct |
24 |
Correct |
18 ms |
37888 KB |
Output is correct |
25 |
Correct |
18 ms |
37880 KB |
Output is correct |
26 |
Correct |
18 ms |
37888 KB |
Output is correct |
27 |
Correct |
22 ms |
37880 KB |
Output is correct |
28 |
Correct |
19 ms |
37888 KB |
Output is correct |
29 |
Correct |
26 ms |
37888 KB |
Output is correct |
30 |
Correct |
18 ms |
37880 KB |
Output is correct |
31 |
Correct |
18 ms |
37888 KB |
Output is correct |
32 |
Correct |
19 ms |
37888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
38016 KB |
Output is correct |
2 |
Correct |
20 ms |
37888 KB |
Output is correct |
3 |
Correct |
19 ms |
38016 KB |
Output is correct |
4 |
Correct |
20 ms |
37888 KB |
Output is correct |
5 |
Correct |
18 ms |
38016 KB |
Output is correct |
6 |
Correct |
20 ms |
38008 KB |
Output is correct |
7 |
Correct |
19 ms |
38016 KB |
Output is correct |
8 |
Correct |
21 ms |
38016 KB |
Output is correct |
9 |
Correct |
22 ms |
37888 KB |
Output is correct |
10 |
Correct |
18 ms |
37888 KB |
Output is correct |
11 |
Correct |
18 ms |
37888 KB |
Output is correct |
12 |
Correct |
19 ms |
37888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
38528 KB |
Output is correct |
2 |
Correct |
22 ms |
38528 KB |
Output is correct |
3 |
Correct |
21 ms |
38784 KB |
Output is correct |
4 |
Correct |
21 ms |
38784 KB |
Output is correct |
5 |
Correct |
21 ms |
38144 KB |
Output is correct |
6 |
Correct |
19 ms |
38272 KB |
Output is correct |
7 |
Correct |
19 ms |
38400 KB |
Output is correct |
8 |
Correct |
19 ms |
37888 KB |
Output is correct |
9 |
Correct |
18 ms |
37888 KB |
Output is correct |
10 |
Correct |
19 ms |
38144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
44672 KB |
Output is correct |
2 |
Correct |
30 ms |
43768 KB |
Output is correct |
3 |
Correct |
30 ms |
47104 KB |
Output is correct |
4 |
Correct |
28 ms |
45432 KB |
Output is correct |
5 |
Correct |
30 ms |
40440 KB |
Output is correct |
6 |
Correct |
26 ms |
40824 KB |
Output is correct |
7 |
Correct |
27 ms |
42112 KB |
Output is correct |
8 |
Correct |
22 ms |
38136 KB |
Output is correct |
9 |
Correct |
22 ms |
40184 KB |
Output is correct |
10 |
Correct |
24 ms |
40064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
58104 KB |
Output is correct |
2 |
Correct |
48 ms |
53368 KB |
Output is correct |
3 |
Correct |
57 ms |
65528 KB |
Output is correct |
4 |
Correct |
47 ms |
56440 KB |
Output is correct |
5 |
Correct |
67 ms |
46584 KB |
Output is correct |
6 |
Correct |
44 ms |
51708 KB |
Output is correct |
7 |
Correct |
43 ms |
49912 KB |
Output is correct |
8 |
Correct |
27 ms |
38528 KB |
Output is correct |
9 |
Correct |
26 ms |
38528 KB |
Output is correct |
10 |
Correct |
52 ms |
45048 KB |
Output is correct |
11 |
Correct |
49 ms |
53752 KB |
Output is correct |
12 |
Correct |
28 ms |
40952 KB |
Output is correct |