#include <bits/stdc++.h>
using namespace std;
struct letter
{
long long l[27],suf,len,cnt;
vector<long long> v;
};
string s;
letter l[300001];
long long last,num;
// curr e vyrhyt S kojto prodyljavame s tek bukva x xSx
void add(long long p)
{
long long i=s[p]-'a';
long long curr=last,len=0;
while(1)
{
len=l[curr].len;
if(p-len-1>=0&&s[p-len-1]==s[p])
break;
curr=l[curr].suf;
}
if(l[curr].l[i])
{
last=l[curr].l[i];
l[last].cnt++;
return;
}
last=++num;
l[num].len=l[curr].len+2;
l[num].cnt=1;
l[curr].l[i]=num;
if(l[num].len==1)
{
l[num].suf=2;
l[2].v.push_back(num);
return;
}
while(1)
{
curr=l[curr].suf;
len=l[curr].len;
if(p-len-1>=0&&s[p-len-1]==s[p])
{
l[num].suf=l[curr].l[i];
l[l[num].suf].v.push_back(num);
break;
}
}
}
void init()
{
num=2;
last=2;
l[1].len=-1;
l[1].suf=1;
l[2].len=0;
l[2].suf=1;
l[1].v.push_back(2);
}
long long sz[300001],ans;
void dfs(long long i)
{
//cout<<i<<endl;
sz[i]=l[i].cnt;
for(long long j=0;j<l[i].v.size();j++)
{
long long nb=l[i].v[j];
dfs(nb);
sz[i]+=sz[nb];
}
ans=max(ans,sz[i]*l[i].len);
}
int main()
{
cin>>s;
init();
for(long long i=0;i<s.size();i++)
add(i);
dfs(1);
cout<<ans<<endl;
return 0;
}
Compilation message
palindrome.cpp: In function 'void dfs(long long int)':
palindrome.cpp:80:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for(long long j=0;j<l[i].v.size();j++)
| ~^~~~~~~~~~~~~~
palindrome.cpp: In function 'int main()':
palindrome.cpp:96:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | for(long long i=0;i<s.size();i++)
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
77904 KB |
Output is correct |
2 |
Correct |
11 ms |
77904 KB |
Output is correct |
3 |
Correct |
10 ms |
77904 KB |
Output is correct |
4 |
Correct |
10 ms |
77904 KB |
Output is correct |
5 |
Correct |
10 ms |
77904 KB |
Output is correct |
6 |
Correct |
10 ms |
77828 KB |
Output is correct |
7 |
Correct |
10 ms |
77904 KB |
Output is correct |
8 |
Correct |
11 ms |
77904 KB |
Output is correct |
9 |
Correct |
10 ms |
77904 KB |
Output is correct |
10 |
Correct |
10 ms |
77824 KB |
Output is correct |
11 |
Correct |
12 ms |
77904 KB |
Output is correct |
12 |
Correct |
12 ms |
77904 KB |
Output is correct |
13 |
Correct |
11 ms |
77904 KB |
Output is correct |
14 |
Correct |
10 ms |
77832 KB |
Output is correct |
15 |
Correct |
10 ms |
77904 KB |
Output is correct |
16 |
Correct |
11 ms |
77904 KB |
Output is correct |
17 |
Correct |
14 ms |
77904 KB |
Output is correct |
18 |
Correct |
14 ms |
77904 KB |
Output is correct |
19 |
Correct |
10 ms |
77904 KB |
Output is correct |
20 |
Correct |
22 ms |
77904 KB |
Output is correct |
21 |
Correct |
17 ms |
77904 KB |
Output is correct |
22 |
Correct |
15 ms |
77904 KB |
Output is correct |
23 |
Correct |
13 ms |
77904 KB |
Output is correct |
24 |
Correct |
19 ms |
77916 KB |
Output is correct |
25 |
Correct |
21 ms |
77920 KB |
Output is correct |
26 |
Correct |
19 ms |
77904 KB |
Output is correct |
27 |
Correct |
11 ms |
77860 KB |
Output is correct |
28 |
Correct |
20 ms |
78076 KB |
Output is correct |
29 |
Correct |
16 ms |
77904 KB |
Output is correct |
30 |
Correct |
16 ms |
77876 KB |
Output is correct |
31 |
Correct |
21 ms |
77904 KB |
Output is correct |
32 |
Correct |
18 ms |
77904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
77904 KB |
Output is correct |
2 |
Correct |
18 ms |
77904 KB |
Output is correct |
3 |
Correct |
18 ms |
78160 KB |
Output is correct |
4 |
Correct |
18 ms |
77904 KB |
Output is correct |
5 |
Correct |
12 ms |
78160 KB |
Output is correct |
6 |
Correct |
19 ms |
78332 KB |
Output is correct |
7 |
Correct |
18 ms |
77904 KB |
Output is correct |
8 |
Correct |
16 ms |
77904 KB |
Output is correct |
9 |
Correct |
13 ms |
77904 KB |
Output is correct |
10 |
Correct |
12 ms |
77904 KB |
Output is correct |
11 |
Correct |
10 ms |
77904 KB |
Output is correct |
12 |
Correct |
10 ms |
77904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
78672 KB |
Output is correct |
2 |
Correct |
15 ms |
78672 KB |
Output is correct |
3 |
Correct |
11 ms |
78892 KB |
Output is correct |
4 |
Correct |
14 ms |
78928 KB |
Output is correct |
5 |
Correct |
11 ms |
78124 KB |
Output is correct |
6 |
Correct |
18 ms |
78416 KB |
Output is correct |
7 |
Correct |
16 ms |
78416 KB |
Output is correct |
8 |
Correct |
15 ms |
77904 KB |
Output is correct |
9 |
Correct |
14 ms |
77904 KB |
Output is correct |
10 |
Correct |
17 ms |
78160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
85068 KB |
Output is correct |
2 |
Correct |
23 ms |
83792 KB |
Output is correct |
3 |
Correct |
31 ms |
88268 KB |
Output is correct |
4 |
Correct |
26 ms |
85976 KB |
Output is correct |
5 |
Correct |
24 ms |
80464 KB |
Output is correct |
6 |
Correct |
25 ms |
80976 KB |
Output is correct |
7 |
Correct |
27 ms |
82248 KB |
Output is correct |
8 |
Correct |
20 ms |
78160 KB |
Output is correct |
9 |
Correct |
23 ms |
80456 KB |
Output is correct |
10 |
Correct |
26 ms |
80208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
99300 KB |
Output is correct |
2 |
Correct |
48 ms |
92660 KB |
Output is correct |
3 |
Correct |
66 ms |
109028 KB |
Output is correct |
4 |
Correct |
63 ms |
97004 KB |
Output is correct |
5 |
Correct |
87 ms |
85988 KB |
Output is correct |
6 |
Correct |
45 ms |
92248 KB |
Output is correct |
7 |
Correct |
50 ms |
89636 KB |
Output is correct |
8 |
Correct |
19 ms |
78816 KB |
Output is correct |
9 |
Correct |
19 ms |
78828 KB |
Output is correct |
10 |
Correct |
75 ms |
84984 KB |
Output is correct |
11 |
Correct |
53 ms |
93320 KB |
Output is correct |
12 |
Correct |
27 ms |
83436 KB |
Output is correct |