//thanks sohsoh :)
#include<bits/stdc++.h>
using namespace std;
string s;
const int maxn=300000+10,maxl=27;
int nxt[maxn][maxl],cnt[maxn],f[maxn],len[maxn],now=0,sz=2;
void solve(int ind){
while(s[ind-len[now]-1]!=s[ind]){
// cout<<ind<<" "<<now<<" "<<len[now]<<"\n";
now=f[now];
}
//cout<<"salam "<<ind<<" "<<now<<" "<<len[now]<<"\n";
int c=s[ind]-'a';
if(nxt[now][c]==0){
nxt[now][c]=sz;
len[sz]=len[now]+2;
now=f[now];
while(s[ind-len[now]-1]!=s[ind]){
now=f[now];
}
if(len[sz]>1){
f[sz]=nxt[now][c];
}
else{
f[sz]=1;
}
now=sz;
cnt[now]++;
sz++;
}
else{
now=nxt[now][c];
cnt[now]++;
}
//cout<<"by "<<f[now]<<"\n";
}
int main(){
len[0]=-1;
f[1]=len[1]=0;
cin>>s;
for(int i=0;i<(int)s.size();i++){
solve(i);
}
long long res=0;
while(sz>1){
res=max(res,1ll*len[sz]*cnt[sz]);
//cout<<sz<<" "<<len[sz]<<" "<<cnt[sz]<<'\n';
cnt[f[sz]]+=cnt[sz];
sz--;
}
cout<<res<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
316 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
316 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
316 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1480 KB |
Output is correct |
2 |
Correct |
2 ms |
1476 KB |
Output is correct |
3 |
Correct |
2 ms |
1492 KB |
Output is correct |
4 |
Correct |
2 ms |
1476 KB |
Output is correct |
5 |
Correct |
2 ms |
1492 KB |
Output is correct |
6 |
Correct |
2 ms |
1492 KB |
Output is correct |
7 |
Correct |
2 ms |
1492 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
12368 KB |
Output is correct |
2 |
Correct |
11 ms |
12372 KB |
Output is correct |
3 |
Correct |
12 ms |
12364 KB |
Output is correct |
4 |
Correct |
11 ms |
12360 KB |
Output is correct |
5 |
Correct |
10 ms |
12364 KB |
Output is correct |
6 |
Correct |
8 ms |
9172 KB |
Output is correct |
7 |
Correct |
9 ms |
10444 KB |
Output is correct |
8 |
Correct |
5 ms |
724 KB |
Output is correct |
9 |
Correct |
6 ms |
3284 KB |
Output is correct |
10 |
Correct |
9 ms |
10576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
36208 KB |
Output is correct |
2 |
Correct |
31 ms |
36196 KB |
Output is correct |
3 |
Correct |
33 ms |
36200 KB |
Output is correct |
4 |
Correct |
42 ms |
36128 KB |
Output is correct |
5 |
Correct |
31 ms |
36160 KB |
Output is correct |
6 |
Correct |
28 ms |
32276 KB |
Output is correct |
7 |
Correct |
28 ms |
30320 KB |
Output is correct |
8 |
Correct |
12 ms |
1128 KB |
Output is correct |
9 |
Correct |
11 ms |
1152 KB |
Output is correct |
10 |
Correct |
27 ms |
29740 KB |
Output is correct |
11 |
Correct |
29 ms |
36196 KB |
Output is correct |
12 |
Correct |
12 ms |
4336 KB |
Output is correct |