Alien Language (Large)
Time limit5sMemory limit512 MB
Given a word list and patterns with letter-group tokens, count for each pattern how many words match it.
- Level
Medium4 of 10
- Topics
- String matching, Brute force
- Solved
- No attempts yet
Problem
A research team decoded an alien language transmitted from a distant planet. Every word of this language is exactly lowercase letters long, and the dictionary holds exactly words.
After the dictionary was finished, the team found that the aliens had been sending signals to Earth for the past ten years. The distance between the two planets weakens the signal, so some letters arrive in a state that can be read in more than one way. Count how many dictionary words a given pattern can stand for.
A pattern is exactly tokens. Each token is either a single lowercase letter or a group of distinct lowercase letters wrapped in the parentheses ( and ). A single-letter token means the letter at that position is fixed, and a group token means the letter at that position is one of the letters inside the group. For example, (ab)d(dc) means the first letter is a or b, the second letter is d, and the third letter is d or c, so it stands for the four words add, adc, bdd, bdc.
Input
The first line contains the integers , , separated by spaces. Each of the next lines contains one word of length . These words are known to exist in the alien language, and they are all different. Each of the following lines contains one pattern in the format described above.
Limits
Output
For each pattern print one line in this format.
Case #X: K
is the pattern number starting from 1, and is the number of dictionary words that match the pattern.