LCS - Longest Common Substring

no tags 

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

hide comments
kiwi1995: 2016-12-13 15:18:14

suffix tree with optimization...pheww...

arun_1997: 2016-12-02 22:08:54

My first implementation of suffix Automaton...

Abdo: 2016-11-03 19:34:26

Weak test cases.

Last edit: 2016-11-03 20:28:09
skmonir: 2016-08-26 12:07:51

After reading comments, i thought it won't get AC using O(NlogN) suffix array. But whoa! AC using O(NlogN) + KasaiLCP in 0.14 sec :D

Last edit: 2016-08-26 12:09:08
square1001: 2016-07-26 13:51:47

O(N) suffix array is very efficient!
Actually, I ever solved this problem in AOJ, so I copied my solution from AOJ :-)

Last edit: 2016-07-26 13:53:22
minhthai: 2016-02-17 05:53:32

O(NlogN) suffix array will not work :(

Dhawal Harkawat: 2016-01-25 14:13:26

After this, try ->

Last edit: 2016-01-25 14:14:04
hanif: 2015-11-16 17:27:56

is it possible to solve this problem with rolling hash technique??

(Tjandra Satria Gunawan)(曾毅昆): 2015-08-21 17:53:02

Optimized Suffix Array -> TLE
Unoptomized Ukkonen -> AC (it's hard for me, need 1 day to understand the concept + 1 day to implement & debug it)
I'm tired but satisfied with this problem ;-)

Omer Farukh: 2015-03-14 19:37:04

Is the answer for given testcase correct ?
I am getting 8 as answer

Added by:Bin Jin
Time limit:0.294s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: C++ 5