Sphere Online Judge

SPOJ Problem Set (classical)

1811. Longest Common Substring

Problem code: LCS


A string is finite sequence of characters over a non-empty finite set Σ.

In this problem, Σ is the set of lowercase letters.

Substring, also called factor, is a consecutive sequence of characters occurrences at least once in a string.

Now your task is simple, for two given strings, find the length of the longest common substring of them.

Here common substring means a substring of two or more strings.

Input

The input contains exactly two lines, each line consists of no more than 250000 lowercase letters, representing a string.

Output

The length of the longest common substring. If such string doesn't exist, print "0" instead.

Example

Input:
alsdfkjfjkdsal
fdjskalajfkdsla

Output:
3

Notice: new testcases added


Added by:Bin Jin
Date:2007-09-24
Time limit:2s
Source limit:50000B
Memory limit:256MB
Cluster: Pyramid (Intel Pentium III 733 MHz)
Languages:All except: C++ 4.0.0-8

hide comments
2014-03-21 18:16:58 zicowa
geting TLE using suffix array O(nlogn) approach
2014-03-20 06:12:57 Terence
AC using O(N) suffix array!
2014-03-17 11:13:21 K NITIN BHARDWAJ
Suffix Automation gets AC:)
2014-01-16 15:55:33 Chandan Mittal
O(NlogN) also TLE

finally!! Suffix Automaton got AC :)

Last edit: 2014-01-18 23:25:00
2013-07-17 07:47:20 jimmy
O(N*log(N)^2) will result in TLE.

Last edit: 2014-04-09 12:01:26
2013-03-15 09:07:25 luyuncheng
why I use DC3 TLE who use DC3 AC?could you please talk to me? luyuncheng@sina.com
2013-03-03 03:49:24 Julio [UFSCar]
My DC3 got TLE. Optimizing a little more...
2013-02-06 19:02:09 Aristofanis Rontogiannis
I don't understand, why is O(N+M) giving me TLE?
2012-11-29 23:48:18 manish sharma
dynamic programming will not work it costs around O(n*m) ...........try suffix tree that will work...complexity O(n+m).

http://en.wikipedia.org/wiki/Longest_common_substring_problem

use the above link
2011-07-17 04:32:18 ymGXX
DC3 can AC....
nlogn TLE....
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.