Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define gc c=getchar()
- #define r(x) read(x)
- #define ll long long
- template<typename T>
- inline void read(T&x){
- x=0;T k=1;char gc;
- while(!isdigit(c)){if(c=='-')k=-1;gc;}
- while(isdigit(c)){x=x*10+c-'0';gc;}x*=k;
- }
- const int N=2e6+7;
- int Max[N];
- int Min[N];
- int to[N][26];
- int fa[N];
- int siz[N];
- int tot;
- inline int NewNode(int mx,int mi,int *tr,int su){
- ++tot;
- Max[tot]=mx;
- Min[tot]=mi;
- if(tr!=NULL)memcpy(to[tot],tr,26<<2);
- fa[tot]=su;
- return tot;
- }
- inline int extend(int u,int c){
- int t=NewNode(Max[u]+1,0,NULL,0);
- siz[t]=1;
- for(;u&&!to[u][c];u=fa[u])to[u][c]=t;
- if(!u){
- Min[t]=1;
- fa[t]=1;
- return t;
- }
- int v=to[u][c];
- if(Max[v]==Max[u]+1){
- Min[t]=Max[v]+1;
- fa[t]=v;
- return t;
- }
- int x=NewNode(Max[u]+1,0,to[v],fa[v]);
- Min[t]=Min[v]=Max[x]+1;
- fa[t]=fa[v]=x;
- Min[x]=Min[fa[x]]+1;
- for(;u&&to[u][c]==v;u=fa[u])to[u][c]=x;
- return t;
- }
- char s[N];
- int deg[N];
- int ans[N];
- queue<int>Q;
- int main(){
- scanf("%s",s);
- int n=strlen(s);
- int lst=NewNode(0,0,NULL,0);
- for(int i=0;i<n;++i){
- lst=extend(lst,s[i]-'a');
- }
- for(int i=2;i<=tot;++i){
- deg[fa[i]]++;
- }
- for(int i=1;i<=tot;++i){
- if(!deg[i]){
- Q.push(i);
- }
- }
- while(!Q.empty()){
- int x=Q.front();Q.pop();
- siz[fa[x]]+=siz[x];
- if(fa[x]&&!--deg[fa[x]]){
- Q.push(fa[x]);
- }
- }
- ll ans=0;
- for(int i=2;i<=tot;++i){
- if(siz[i]>1){
- ans=max(ans,(ll)siz[i]*Max[i]);
- }
- }
- printf("%lld\n",ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement