제출 #739948

#제출 시각아이디문제언어결과실행 시간메모리
739948amirhoseinfar1385회문 (APIO14_palindrome)C++17
100 / 100
42 ms36208 KiB
//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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...