#include <iostream>
#include <fstream>
using namespace std;
const int nmax=300005;
struct fft
{
int len,link,ap;
int son[26];
}v[nmax];
string s;
int wh[nmax];
int nodes,p,ch,i;
long long ans;
void primul_chef()
{
nodes=2;
v[1].len=-1;
v[1].link=v[2].link=1;
wh[0]=2;
}
void ins(int poz)
{
p=wh[poz-1];ch=s[poz]-'a';
while(s[poz]!=s[poz-v[p].len-1])
p=v[p].link;
if(v[p].son[ch])
{
v[v[p].son[ch]].ap++;
wh[poz]=v[p].son[ch];
return;
}
++nodes;
wh[poz]=nodes;
v[p].son[ch]=nodes;
v[nodes].len=v[p].len+2;
v[nodes].ap=1;
if(v[nodes].len==1)
{
v[nodes].link=2;
return;
}
p=v[p].link;
while(s[poz]!=s[poz-v[p].len-1])
p=v[p].link;
v[nodes].link=v[p].son[ch];
}
int main()
{
ios_base::sync_with_stdio(false);
cin>>s;s=" "+s;
primul_chef();
for(i=1;i<s.size();i++)
ins(i);
for(i=nodes;i>=1;i--)
{
v[v[i].link].ap+=v[i].ap;
ans=max(ans,1LL*v[i].len*v[i].ap);
}
cout<<ans;
return 0;
}
Compilation message
palindrome.cpp: In function 'int main()':
palindrome.cpp:52:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=1;i<s.size();i++)
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
632 KB |
Output is correct |
13 |
Correct |
2 ms |
636 KB |
Output is correct |
14 |
Correct |
2 ms |
640 KB |
Output is correct |
15 |
Correct |
2 ms |
676 KB |
Output is correct |
16 |
Correct |
2 ms |
680 KB |
Output is correct |
17 |
Correct |
2 ms |
684 KB |
Output is correct |
18 |
Correct |
2 ms |
688 KB |
Output is correct |
19 |
Correct |
2 ms |
692 KB |
Output is correct |
20 |
Correct |
3 ms |
700 KB |
Output is correct |
21 |
Correct |
3 ms |
700 KB |
Output is correct |
22 |
Correct |
2 ms |
704 KB |
Output is correct |
23 |
Correct |
2 ms |
724 KB |
Output is correct |
24 |
Correct |
2 ms |
748 KB |
Output is correct |
25 |
Correct |
2 ms |
852 KB |
Output is correct |
26 |
Correct |
2 ms |
852 KB |
Output is correct |
27 |
Correct |
2 ms |
852 KB |
Output is correct |
28 |
Correct |
2 ms |
852 KB |
Output is correct |
29 |
Correct |
2 ms |
852 KB |
Output is correct |
30 |
Correct |
2 ms |
852 KB |
Output is correct |
31 |
Correct |
2 ms |
852 KB |
Output is correct |
32 |
Correct |
2 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
896 KB |
Output is correct |
2 |
Correct |
2 ms |
896 KB |
Output is correct |
3 |
Correct |
3 ms |
900 KB |
Output is correct |
4 |
Correct |
2 ms |
904 KB |
Output is correct |
5 |
Correct |
2 ms |
904 KB |
Output is correct |
6 |
Correct |
2 ms |
912 KB |
Output is correct |
7 |
Correct |
2 ms |
916 KB |
Output is correct |
8 |
Correct |
2 ms |
928 KB |
Output is correct |
9 |
Correct |
2 ms |
928 KB |
Output is correct |
10 |
Correct |
3 ms |
928 KB |
Output is correct |
11 |
Correct |
2 ms |
928 KB |
Output is correct |
12 |
Correct |
2 ms |
928 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 |
1992 KB |
Output is correct |
4 |
Correct |
3 ms |
2000 KB |
Output is correct |
5 |
Correct |
4 ms |
2012 KB |
Output is correct |
6 |
Correct |
4 ms |
2024 KB |
Output is correct |
7 |
Correct |
4 ms |
2084 KB |
Output is correct |
8 |
Correct |
2 ms |
2084 KB |
Output is correct |
9 |
Correct |
3 ms |
2084 KB |
Output is correct |
10 |
Correct |
3 ms |
2084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
12900 KB |
Output is correct |
2 |
Correct |
14 ms |
13060 KB |
Output is correct |
3 |
Correct |
14 ms |
13160 KB |
Output is correct |
4 |
Correct |
14 ms |
13260 KB |
Output is correct |
5 |
Correct |
18 ms |
13292 KB |
Output is correct |
6 |
Correct |
13 ms |
13292 KB |
Output is correct |
7 |
Correct |
17 ms |
13292 KB |
Output is correct |
8 |
Correct |
5 ms |
13292 KB |
Output is correct |
9 |
Correct |
8 ms |
13292 KB |
Output is correct |
10 |
Correct |
16 ms |
13292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
37852 KB |
Output is correct |
2 |
Correct |
45 ms |
38140 KB |
Output is correct |
3 |
Correct |
41 ms |
38408 KB |
Output is correct |
4 |
Correct |
41 ms |
38796 KB |
Output is correct |
5 |
Correct |
54 ms |
39064 KB |
Output is correct |
6 |
Correct |
40 ms |
39064 KB |
Output is correct |
7 |
Correct |
37 ms |
39064 KB |
Output is correct |
8 |
Correct |
9 ms |
39064 KB |
Output is correct |
9 |
Correct |
9 ms |
39064 KB |
Output is correct |
10 |
Correct |
53 ms |
39064 KB |
Output is correct |
11 |
Correct |
38 ms |
40968 KB |
Output is correct |
12 |
Correct |
12 ms |
40968 KB |
Output is correct |