标签:des style blog http color io os ar strong
Time Limit: 4000MS | Memory Limit: 131072K | |
Case Time Limit: 1000MS |
Description
Input
Output
Sample Input
yeshowmuchiloveyoumydearmotherreallyicannotbelieveit yeaphowmuchiloveyoumydearmother
Sample Output
27
Source
1 #include<set> 2 #include<map> 3 #include<queue> 4 #include<cstdio> 5 #include<cstdlib> 6 #include<cstring> 7 #include<iostream> 8 #include<algorithm> 9 using namespace std; 10 const int N = 100100; 11 typedef unsigned long long ull; 12 const ull K = 10000007; 13 #define For(i,n) for(int i=1;i<=n;i++) 14 #define For0(i,n) for(int i=0;i<n;i++) 15 #define Rep(i,l,r) for(int i=l;i<=r;i++) 16 #define Down(i,r,l) for(int i=r;i>=l;i--) 17 //set<ull> q; 18 ull q[N]; 19 char st1[N],st2[N]; 20 int l,r,len1,len2,tail; 21 ull f1[N],f2[N],pows[N]; 22 23 bool Check(int len){ 24 // q.clear(); 25 //q.insert(f1[len-1]); 26 q[++tail]=f1[len-1]; 27 Rep(i,len+1,len1) q[++tail]=(f1[i-1]-f1[i-len-1]*pows[len]); 28 sort(q+1,q+tail+1); 29 //if(q.count(f2[len-1])) return true; 30 if(q[lower_bound(q+1,q+tail+1,f2[len-1])-q]==f2[len-1]) return true; 31 Rep(i,len+1,len2) 32 // if(q.count(f2[i-1]-f2[i-len-1]*pows[len])) return true; 33 if(q[lower_bound(q+1,q+tail+1,(f2[i-1]-f2[i-len-1]*pows[len]))-q] 34 ==(f2[i-1]-f2[i-len-1]*pows[len])) return true; 35 return false; 36 } 37 38 void GetHash(char *st,ull *F){ 39 int len=strlen(st); 40 F[0]=st[0]; 41 For(i,len) F[i]=F[i-1]*K+st[i]; 42 F[len]=F[len-1]*K; 43 } 44 45 void init(){ 46 pows[0]=1; 47 For(i,N-1) pows[i]=pows[i-1]*K; 48 scanf("%s",st1);scanf("%s",st2); 49 len1=strlen(st1);len2=strlen(st2); 50 } 51 52 int main(){ 53 init(); 54 GetHash(st1,f1);GetHash(st2,f2); 55 r=min(len1,len2); 56 while(r-l>1){ 57 int Mid=(l+r)>>1;tail=0; 58 if(Check(Mid)) l=Mid; 59 else r=Mid; 60 }tail=0; 61 if(Check(r)) printf("%d\n",r); 62 else printf("%d\n",l); 63 return 0; 64 }
标签:des style blog http color io os ar strong
原文地址:http://www.cnblogs.com/kingnight/p/3989182.html