Capital OneOA #12
Recipes — Is Each Recipe a Prep-list Combination?
Estimated MediumJudge-ready
Topics (AI-labelled)Strings
You are given ingredient strings ingredients and several recipe strings. A recipe is a prep-list combination if it can be split into one or more contiguous non-empty pieces, each exactly equal to some string in ingredients. Decide this for each recipe.
Input
The first line contains n r (1≤n,r≤200000), followed by n lines of non-empty lowercase ingredient names, then r lines of non-empty lowercase recipe strings. This site's supplementary ranges: each ingredient has length ≤100, and the total number of ingredient characters is ≤200000; the total number of recipe characters is ≤100000, and maximum ingredient length × total recipe characters ≤10^7. The input format and performance ranges above are this site's supplement.
Output
Output YES or NO for each recipe in input order, separated by spaces.
Example 1
Input:
3 5
flour
sugar
eggs
floursugar
random
flour
sugarflour
sugareggs
Output:
YES NO YES YES YES
Example 2
Input:
2 3
a
ab
ab
aba
b
Output:
YES YES NO
Example 3
Input:
1 3
xy
xy
xyxy
x
Output:
YES YES NO
Editorial
Loading solution…