Shortest Missing Subsequences
Time limit10sMemory limit1024 MB
Given a target string and queries over an alphabet, decide for each query whether it is a shortest string that is not a subsequence of the target.
- Level
Hard8 of 10
- Topics
- String, Greedy, Dynamic programming, Hash map
- Solved
- No attempts yet
Problem
Given a string , a string is a subsequence of if can be obtained from by deleting zero or more characters of . Note that is not necessarily a substring of : the characters of need not be contiguous in , but they must appear in the same order as they do in .
For a given subset of the lowercase English letters from 'a' to 'z', a string is a missing subsequence of a string if is not a subsequence of , and every character of and every character of belongs to . A shortest missing subsequence of is a missing subsequence of whose length is the smallest among all missing subsequences of .
You are given a set of English letters, a target string made up of characters from that set, and a list of query strings made up of characters from that set. For each query string, determine whether it is a shortest missing subsequence of the target string.
Input
The first line contains a string () of lowercase letters in lexicographical order. Each letter appears at most once. This is the set of letters.
The second line contains a string (; contains only letters from ). This is the target string.
The third line contains an integer (), the number of queries.
Each of the next lines contains a string (; contains only letters from ). These are the query strings. The sum of the lengths of all query strings does not exceed .
Output
Output lines. On each line, output if the query string is a shortest missing subsequence of the target string, or if it is not. The outputs must be in the order of the input queries.