首页 > 题解 > spoj 1811 Longest Common Substring

spoj 1811 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.

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

题解

大概就是裸题了吧。。对一个串造个SAM,另一个串放上去匹配,记录下最长走多少。

注意这题只能$O(n)$做。。spoj真是老爷机,这题$O(n \log n)$都T。啧啧啧


1 COMMENT

如果你觉的这篇文章不错,分享给朋友吧!

打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮

×