题目连接:
https://vjudge.net/problem/SPOJ-LCS
Description
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.
Sample Input
alsdfkjfjkdsal
fdjskalajfkdsla
Sample Output
3
Hint
题意
求两个串的最长公共子串长度
题解:
对a串建后缀自动机,b串在建好的自动机上跑,跑的过程和建树是一样的,如果Next[p][c]存在则nowlen++,否则p回退到fa[p]直到Next[p][c]存在,并更新nowlen为len[p]+1,对整个过程的nowlen取max就是答案
代码
1 |
|