이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |