#P6139. 【模板】广义后缀自动机(广义 SAM)
【模板】广义后缀自动机(广义 SAM)
Description
Given strings consisting of lowercase letters, find the number of distinct substrings (excluding the empty string).
Furthermore, let be the minimal DFA that can accept all suffixes of . Please output the number of states in . (If you cannot understand this sentence, you may treat it as outputting the number of states of the "generalized suffix automaton" built from .)
Input Format
The first line contains a positive integer .
The next lines each contain a string. The -th line represents the string .
Output Format
The first line contains a positive integer: the number of distinct substrings.
The second line contains a positive integer: the number of states in .
4
aa
ab
bac
caa
10
10
1
a
1
2
Hint
Constraints: , .
Sample 1 explanation: There are distinct substrings: "a","b","c","aa","ab","ac","ba","ca","bac","caa". The DFA structure is omitted.
Sample 2 explanation: There is distinct substring: "a". The DFA contains a start state and a state , with an edge labeled a. Therefore, the total number of states is .
Translated by ChatGPT 5
京公网安备 11011102002149号