好像这个不是最优算法。。。但是确实是个模板题
#include <cstdio>
#include <cmath>#include <ctime>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include<map>
#include<list>
#define pb push_back
#define lb lower_bound
#define sqr(x) (x)*(x)
#define lowbit(x) (x)&(-x)
#define Abs(x) ((x) > 0 ? (x) : (-(x)))
#define forup(i,a,b) for(int i=(a);i<=(b);i++)
#define fordown(i,a,b) for(int i=(a);i>=(b);i--)
#define ls(a,b) (((a)+(b)) << 1)
#define rs(a,b) (((a)+(b)) >> 1)
#define getlc(a) ch[(a)][0]
#define getrc(a) ch[(a)][1]
#define maxn 400005
#define maxm 100005
#define INF 1070000000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline
void read(T& num){
num = 0; bool f = true;char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') f = false;ch = getchar();}
while(ch >= '0' && ch <= '9') {num = num * 10 + ch - '0';ch = getchar();}
num = f ? num: -num;
}
int out[100];
template<class T> inline
void write(T x,char ch){
if (x==0) {putchar('0'); putchar(ch); return;}
if (x<0) {putchar('-'); x=-x;}
int num=0;
while (x){ out[num++]=(x%10); x=x/10;}
fordown(i,num-1,0) putchar(out[i]+'0'); putchar(ch);
}
/*==================split line==================*/
int n;
int a[maxn];
int sum[maxn],rk[maxn],r1[maxn],r2[maxn],sa1[maxn],sa2[maxn],height[maxn];
char str1[maxn],str2[maxn];
void solve()
{
memset(sum,0,sizeof(sum));
forup(i,1,n) sum[a[i]]++;
forup(i,1,26) sum[i]+=sum[i-1];
forup(i,1,n) rk[i]=sum[a[i]-1]+1;
int k=1;
while(k<n)
{ forup(i,1,n)
{r1[i]=rk[i];
if(i+k<=n) r2[i]=rk[i+k];
else r2[i]=0;
}
memset(sum,0,sizeof(sum));
forup(i,1,n) sum[r2[i]]++;
forup(i,1,n) sum[i]+=sum[i-1];
fordown(i,n,1) sa2[sum[r2[i]]]=i,sum[r2[i]]--;
memset(sum,0,sizeof(sum));
forup(i,1,n) sum[r1[i]]++;
forup(i,1,n) sum[i]+=sum[i-1];
fordown(i,n,1) sa1[sum[r1[sa2[i]]]]=sa2[i],sum[r1[sa2[i]]]--;
rk[sa1[1]]=1;
forup(i,2,n)
{rk[sa1[i]]=rk[sa1[i-1]];
if(!(r1[sa1[i]]==r1[sa1[i-1]]&&r2[sa1[i]]==r2[sa1[i-1]])) rk[sa1[i]]++;
}
k=k<<1;
}
height[1]=0;int l=0;
forup(i,1,n)
{ if(rk[i]>1)
{ int k=sa1[rk[i]-1];
while(i+l<=n&&k+l<=n&&a[i+l]==a[k+l]) l++;
height[rk[i]]=l;
if(l>0) l--;
}
}
}
int main()
{ while(~scanf("%s%s",str1,str2))
{ int len1=strlen(str1),len2=strlen(str2);
forup(i,0,len1-1) a[i+1]=str1[i]-96;//1~26
a[len1+1]=27;
forup(i,0,len2-1) a[len1+i+1+1]=str2[i]-96;
n=len1+len2+1;
solve();
int ans=0;
forup(i,1,n)
{if((sa1[i]<=len1&&sa1[i-1]>len1)||(sa1[i]>len1&&sa1[i-1]<=len1))
ans=max(ans,height[i]);
}
write(ans,'\n');
}
return 0;
}