[Solution] Color with Occurrences Codeforces Solution
You are given some text and a set of strings .
In one step, you can choose any occurrence of any string in the text and color the corresponding characters of the text in red. For example, if and , , you can get , or in one step.
You want to color all the letters of the text in red. When you color a letter in red again, it stays red.
In the example above, three steps are enough:
- Let's color in red, we get ;
- Let's color in red, we get ;
- Let's color in red, we get .
Each string can be applied any number of times (or not at all). Occurrences for coloring can intersect
occupied
arbitrarily.
Determine the minimum number of steps needed to color all letters in red and how to do it. If it is impossible to color all letters of the text in red, output -1.
The first line of the input contains an integer () —the number of test cases in the test.
The descriptions of the test cases follow.
The first line of each test case contains the text (), consisting only of lowercase Latin letters, where is the length of the text .
The second line of each test case contains a single integer () — the number of strings in the set.
This is followed by lines, each containing a string () consisting only of lowercase Latin letters, where — the length of string .
For each test case, print the answer on a separate line.
If it is impossible to color all the letters of the text in red, print a single line containing the number -1.
Otherwise, on the first line, print the number — the minimum number of steps it will take to turn all the letters red.
Then in the next lines print pairs of indices: and (), which denote that the line with index was used as a substring to cover the occurrences starting in the text from position . The pairs can be output in any order.
If there are several answers, output any of them.
No comments:
Post a Comment