Boring Lesson
Time limit1sMemory limit512 MB
Given strings s and t and a list of n favorite strings, find the minimum edit distance from s to t and the largest subset of favorites that can all appear along a shortest edit path, then output that subset in order.
- Level
Hard9 of 10
- Topics
- Dynamic programming, String, Graph, Shortest path
- Solved
- No attempts yet
Problem
Ildar is attending a boring online lesson. To have something to do, he transforms strings. Initially, he has a string . Ildar wants to obtain a string from the string in the minimum number of steps. In one step he can:
- Remove a character from any position.
- Insert any character at any position. That is, before the first character, between two adjacent characters, or after the last character.
- Replace the character at any position with any other character.
The minimum number of such steps needed to transform string into string is also known as the edit distance between and .
Ildar has favorite strings . Consider the sequence of strings that occur during the transformation: , , \dots, , . Ildar wants as many of the as possible to appear in the set . Help Ildar find the minimum number of steps needed to transform into and the maximum number of that can appear during this process, and print those strings as well.
Input
The first line of input contains the string .
The second line of input contains the string .
The third line contains a single integer (). The following lines contain strings .
All strings consist of lowercase English letters, are non-empty, and their lengths do not exceed . The total length of all strings does not exceed . All strings are distinct, including , , and .
Output
On the first line of output, print two integers: the minimum number of steps needed to transform into , and the maximum number of strings that can appear during the transformation.
After that, print the strings that can appear during the transformation, in the order in which they would appear. If there are multiple correct answers, you can print any of them.
Notes
In the second example, one correct transformation is the following:
"longlong" "longleng" "dongleng" "dongleg" "dongle" "donble" "double"
Ildar's favorite strings are highlighted.