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.


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


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




Notice: new testcases added

Added by:Bin Jin
Time limit:0.294s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel Pentium G860 3GHz)
Languages:All except: C++ 4.0.0-8

hide comments
2014-10-16 22:11:06 Gaurav Kumar Verma
Suffix Automation got AC in C++ but got TLE in JAVA, i dont understand y :(
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).


use the above link
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.