LCS - Longest Common Substring
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.
Input: alsdfkjfjkdsal fdjskalajfkdsla Output: 3
Notice: new testcases added
manber-myers works for me :-)
As the example of Suffix automation,this problem is so classic!
O(NlogN) suffix array won't work. You need to implement the O(N) suffix tree/suffix automaton for this.
first i got TLE using suffix Automaton and dp and by changing the suffix Automaton algorithem i get AC with a good time ( it turns out that the old suffix Automaton implementation was very slow )
Last edit: 2017-02-28 14:03:40
suffix tree with optimization...pheww...
My first implementation of suffix Automaton...
Weak test cases.
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 :DLast edit: 2016-08-26 12:09:08
O(N) suffix array is very efficient!