Time Limit: 4000MS | Memory Limit: 131072K | |
Total Submissions: 29589 | Accepted: 12018 | |
Case Time Limit: 1000MS |
Descriptionios
Inputapi
Output數組
Sample Inputapp
yeshowmuchiloveyoumydearmotherreallyicannotbelieveit yeaphowmuchiloveyoumydearmother
Sample Outputless
27
Sourceide
#include<cstdio> #include<cstring> #include<iostream> using namespace std; const int N=2e5+10; int n,len,ans,maxx,sa[N],tsa[N],rank[N],trank[N],h[N],c[N]; char s[N]; void DA(){ int p; memset(c,0,sizeof c);maxx=256; for(int i=1;i<=len;i++) c[rank[i]=s[i]]++; for(int i=2;i<=maxx;i++) c[i]+=c[i-1]; for(int i=len;i;i--) sa[c[rank[i]]--]=i; trank[sa[1]]=p=1; for(int i=2;i<=len;i++){ if(rank[sa[i]]!=rank[sa[i-1]]) p++; trank[sa[i]]=p; } for(int i=1;i<=len;i++) rank[i]=trank[i]; for(int k=1;p<len;k<<=1,maxx=p){ p=0; for(int i=len-k+1;i<=len;i++) tsa[++p]=i; for(int i=1;i<=len;i++) if(sa[i]>k) tsa[++p]=sa[i]-k; memset(c,0,sizeof c); for(int i=1;i<=len;i++) trank[i]=rank[tsa[i]]; for(int i=1;i<=len;i++) c[trank[i]]++; for(int i=2;i<=maxx;i++) c[i]+=c[i-1]; for(int i=len;i;i--) sa[c[trank[i]]--]=tsa[i]; trank[sa[1]]=p=1; for(int i=2;i<=len;i++){ if(rank[sa[i]]!=rank[sa[i-1]]||rank[sa[i]+k]!=rank[sa[i-1]+k]) p++; trank[sa[i]]=p; } for(int i=1;i<=len;i++) rank[i]=trank[i]; } for(int i=1,k=0;i<=len;i++){ int j=sa[rank[i]-1]; while(s[i+k]==s[j+k]) k++; h[rank[i]]=k;if(k>0) k--; } } int main(){ scanf("%s",s+1);len=strlen(s+1);s[++len]='$';n=len+1; scanf("%s",s+n);len=strlen(s+1); DA(); for(int i=2;i<=len;i++){//0.5h打完 2h調錯 QAQ if((sa[i]>=n&&sa[i-1]<n)||(sa[i-1]>=n&&sa[i]<n)){ ans=max(ans,h[i]); } } printf("%d",ans); return 0; }