Time Limit: 4000MS |
|
Memory Limit: 131072K |
Total Submissions: 25018 |
|
Accepted: 10237 |
Case Time Limit: 1000MS |
Description
The little cat is majoring in physics in the capital of Byterland. A piece of sad news comes to him these days:his mother is getting ill. Being worried about spending so much in railway tickets (Byterland is such a big country, and he have to spend all shours on Train to him hometown), he decided only to send SMS with his mother.
The little cat lives in a Unrich family, so he frequently comes to the Mobile service center, to check how much money He has spent on SMS. Yesterday, the computer of service center was broken, and printed, very long messages. The brilliant little cat soon found out:
1. All characters in messages is lowercase Latin letters, without punctuations and spaces.
2. All SMS have been appended other– (i+1)-th SMS comes directly after the i-th One–that are why those both me Ssages is quite long.
3. His own SMS have been appended together, but possibly a great many redundancy characters appear leftwards and RIGHTW Ards due to the broken computer.
e.g:if his SMS was "motheriloveyou", either long message printed by, the would possibly be one of "hahamother Iloveyou "," motheriloveyoureally "," Motheriloveyouornot "," bbbmotheriloveyouaaa ", etc.
4. For these broken issues, the little cat have printed his original text twice (so there appears both very long message s). Even though the original text remains the same in both printed messages, the redundancy characters on both sides would Be possibly different.
You are given those-very long messages, and you had to output the length of the longest possible original text WR Itten by the little cat.
Background:
The SMS in Byterland Mobile service is charging in Dollars-per-byte. That's why the little cat was worrying about how long could the longest original text being.
Why do I ask you to write a program? There is four resions:
1. The little cat is so busy these days with physics lessons;
2. The little cat wants to keep what he said to his mother Seceret;
3. POJ is such a great Online Judge;
4. The little cat wants to earn some money from POJ, and try to persuade he mother to see the Doctor:(
Input
The strings with lowercase letters on the input lines individually. number of characters in each one would never exceed 100000.
Output
A single line with a single integer number–what are the maximum length of the original text written by the little Cat .
Sample Input
Yeshowmuchiloveyoumydearmotherreallyicannotbelieveityeaphowmuchiloveyoumydearmother
Sample Output
27
Source
POJ Monthly--2006.03.26,zeyuan Zhu, "Dedicate to my great beloved mother."
The following:
Test Instructions:topic given two strings A, b, for the longest common substring of a and B.
Conversions: because the substring must be a prefix for a suffix, the problem is equivalent to the maximum value of the longest public prefix in the suffix of a and B. With the help of the height[] array, we let a string and B string together to form a new string T, take the height of the value, but to ensure that the current height[i] I meet the suffix of the rank I and the suffix of the rank i-1 are distributed in a A, b two string.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <queue>7#include <vector>8 using namespacestd;9 Const intmaxn=200000;Ten intR[MAXN],SA[MAXN],WA[MAXN],WB[MAXN],WV[MAXN],WS[MAXN]; One intcmpint*r,intAintBintl) { A returnr[a]==r[b]&&r[a+l]==r[b+l]; - } - voidDaint*r,int*sa,intNintm) { the inti,j,p,*x=wa,*y=wb,*T; - for(i=0; i<m;i++) ws[i]=0; - for(i=0; i<n;i++) ws[x[i]=r[i]]++; - for(i=1; i<m;i++) ws[i]+=ws[i-1]; + for(i=n-1; i>=0; i--) sa[--ws[x[i]]]=i; - + for(j=1, p=1;p <n;j*=2, m=p) { A for(p=0, i=n-j;i<n;i++) y[p++]=i; at for(i=0; i<n;i++)if(SA[I]>=J) y[p++]=sa[i]-J; - - for(i=0; i<n;i++) wv[i]=X[y[i]]; - for(i=0; i<m;i++) ws[i]=0; - for(i=0; i<n;i++) ws[wv[i]]++; - for(i=1; i<m;i++) ws[i]+=ws[i-1]; in for(i=n-1; i>=0; i--) sa[--ws[wv[i]]]=Y[i]; - to for(t=x,x=y,y=t,p=1, i=1, x[sa[0]]=0; i<n;i++) +X[SA[I]]=CMP (y,sa[i-1],sa[i],j)? p1:p + +; - } the } * intRANK[MAXN],HEIGHT[MAXN]; $ voidCalheight (int*r,int*sa,intN) {Panax Notoginseng inti,j,k=0; - for(i=0; i<n;i++) rank[sa[i]]=i; the for(i=0; i<n;height[rank[i++]]=k) + for(k?k--:0, j=sa[rank[i]-1];r[i+k]==r[j+k];k++); A return ; the } + CharS1[MAXN],S2[MAXN]; - intLen1,len2,now,num[maxn],ans; $ intMain () { $scanf"%s%s", S1,S2); Len1=strlen (S1); Len2=strlen (S2); - for(intI=0; i<len1;i++) num[now++]=s1[i]-'a'+2; -num[now++]=1; the for(intI=0; i<len2;i++) num[now++]=s2[i]-'a'+2; -Da (Num,sa,now, -);Wuyi calheight (num,sa,now); the for(intI=1; i<now;i++) - if((sa[i]<len1&&sa[i-1]>LEN1) | | (sa[i-1]<len1&&sa[i]>len1)) Wuans=Max (ans,height[i]); -printf"%d", ans); About return 0; $}
POJ 2774:long Long Message