#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xx first
#define yy second
#define ff(i,s,f) for(ll i=s;i<f;i++)
#define fb(i,s,f) for(ll i=(s)-1;i>=f;i--)
#define ffi(i,s,f) for(ll i=s;i<=f;i++)
#define fbi(i,s,f) for(ll i=s;i>=f;i--)
#define srt(a) sort(a.begin(),a.end());
#define srtg(a,ll) sort(a.begin(),a.end(),greater<ll>())
#define lb(a,x) lower_bound(a.begin(),a.end(),x)
#define ub(a,x) upper_bound(a.begin(),a.end(),x)
#define fnd(a,x) find(a.begin(),a.end(),x)
#define vstart auto startt=chrono::system_clock::now()
#define vend auto endd=chrono::system_clock::now()
#define vvreme chrono::duration<double> vremee=endd-startt
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<ll,ll> pll;
typedef string str;
struct node{
ll dje[26];
ll be=0,cnt=0,len=0;
};
vector<node> pt;
node prazan;
ll tren;
string s;
void addletter(ll i){
if(pt[tren].len==i) tren=pt[tren].be;
while(s[i-pt[tren].len-1]!=s[i]){
tren=pt[tren].be;
}
if(pt[tren].dje[s[i]-'a']==0){
pt.push_back(prazan);
pt[tren].dje[s[i]-'a']=pt.size()-1;
}
ll len=pt[tren].len+2;
ll be=-1;
ll ntren=tren;
tren=pt[tren].dje[s[i]-'a'];
pt[tren].len=len;
pt[tren].cnt++;
if(ntren==1){
be=2;
pt[tren].be=be;
}else{
ntren = pt[ntren].be;
while(s[i-pt[ntren].len-1]!=s[i]){
ntren=pt[ntren].be;
}
be=ntren;
if(pt[be].dje[s[i]-'a']==0){
pt.push_back(prazan);
pt[be].dje[s[i]-'a']=pt.size()-1;
}
pt[tren].be=pt[be].dje[s[i]-'a'];
}
}
void init(){
pt.clear();
pt.push_back(prazan);
pt.push_back(prazan);
pt.push_back(prazan);
pt[1].len=-1;
pt[1].be=1;
pt[2].len=0;
pt[2].be=1;
tren=1;
}
void solve(){
cin>>s;
init();
for(ll i=0;i<s.size();i++) addletter(i);
for(ll i=(ll)pt.size()-1;i>=1;i--){
pt[pt[i].be].cnt+=pt[i].cnt;
}
ll maxi=-1;
for(ll i=1;i<pt.size();i++){
maxi=max(maxi,pt[i].cnt*pt[i].len);
}
cout<<maxi;
}
int main(){
ios;
ll t=1;
//cin>>t;
while(t--) solve();
return 0;
}
Compilation message
palindrome.cpp: In function 'void solve()':
palindrome.cpp:89:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for(ll i=0;i<s.size();i++) addletter(i);
| ~^~~~~~~~~
palindrome.cpp:94:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for(ll i=1;i<pt.size();i++){
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
332 KB |
Output is correct |
23 |
Correct |
0 ms |
332 KB |
Output is correct |
24 |
Correct |
0 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
0 ms |
332 KB |
Output is correct |
28 |
Correct |
0 ms |
332 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
0 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
616 KB |
Output is correct |
2 |
Correct |
1 ms |
616 KB |
Output is correct |
3 |
Correct |
1 ms |
616 KB |
Output is correct |
4 |
Correct |
1 ms |
616 KB |
Output is correct |
5 |
Correct |
1 ms |
616 KB |
Output is correct |
6 |
Correct |
1 ms |
616 KB |
Output is correct |
7 |
Correct |
1 ms |
616 KB |
Output is correct |
8 |
Correct |
1 ms |
616 KB |
Output is correct |
9 |
Correct |
1 ms |
616 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4104 KB |
Output is correct |
2 |
Correct |
3 ms |
4104 KB |
Output is correct |
3 |
Correct |
3 ms |
4104 KB |
Output is correct |
4 |
Correct |
3 ms |
4104 KB |
Output is correct |
5 |
Correct |
4 ms |
4104 KB |
Output is correct |
6 |
Correct |
3 ms |
4116 KB |
Output is correct |
7 |
Correct |
3 ms |
4104 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
2220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
30364 KB |
Output is correct |
2 |
Correct |
23 ms |
30364 KB |
Output is correct |
3 |
Correct |
26 ms |
30364 KB |
Output is correct |
4 |
Correct |
27 ms |
30352 KB |
Output is correct |
5 |
Correct |
26 ms |
30364 KB |
Output is correct |
6 |
Correct |
27 ms |
30308 KB |
Output is correct |
7 |
Correct |
23 ms |
30364 KB |
Output is correct |
8 |
Correct |
3 ms |
844 KB |
Output is correct |
9 |
Correct |
8 ms |
8100 KB |
Output is correct |
10 |
Correct |
24 ms |
30356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
119668 KB |
Output is correct |
2 |
Correct |
87 ms |
119672 KB |
Output is correct |
3 |
Correct |
89 ms |
119744 KB |
Output is correct |
4 |
Correct |
87 ms |
119660 KB |
Output is correct |
5 |
Correct |
95 ms |
119744 KB |
Output is correct |
6 |
Correct |
84 ms |
119740 KB |
Output is correct |
7 |
Correct |
59 ms |
60224 KB |
Output is correct |
8 |
Correct |
9 ms |
1288 KB |
Output is correct |
9 |
Correct |
6 ms |
1236 KB |
Output is correct |
10 |
Correct |
69 ms |
60152 KB |
Output is correct |
11 |
Correct |
85 ms |
119708 KB |
Output is correct |
12 |
Correct |
13 ms |
8136 KB |
Output is correct |