#P6139. 【模板】广义后缀自动机(广义 SAM)
【模板】广义后缀自动机(广义 SAM)
Background
Admin note: This problem added the requirement to output the number of states on May 4, 2023. Solutions submitted before that did not output the number of states, hereby noted.
Problem 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