Mysterious Device
Time limit2sMemory limit1024 MB
Given buttons that append fixed strings or delete a set number of characters, decide for each query string whether the screen can end up showing it.
- Level
Medium7 of 10
- Topics
- String matching, Trie, Dynamic programming
- Solved
- No attempts yet
Problem
Dima has a device with buttons and a screen. The screen shows a string , which is initially empty.
Pressing button () appends the string to the end of . Pressing button () removes characters from the end of . If has fewer than characters, it becomes empty.
Dima has favorite strings . For each one, determine whether he can make equal to by pressing buttons some number of times, starting from the empty string .
Input
The first line contains two integers and (), the number of buttons of the first and second type.
The next lines contain non-empty strings consisting of lowercase English letters. The total length of all strings does not exceed .
The next lines contain integers ().
The next line contains an integer (), the number of Dima's favorite strings.
The next lines contain non-empty strings consisting of lowercase English letters. The total length of all strings does not exceed .
Output
For each string , print Yes on its own line if can be made equal to , and No otherwise.