#P2292. [HNOI2004] L 语言
[HNOI2004] L 语言
Description
Punctuation appeared later than writing, so earlier languages had no punctuation. Now you need to process an article without punctuation.
An article consists of lowercase letters. A word also consists of lowercase letters. A dictionary is a set of words. We say an article is understandable under a dictionary if can be split into several parts and each part is a word in .
For example, if the dictionary includes the words $\texttt{is}, \texttt{name}, \texttt{what}, \texttt{your}$, then the article whatisyourname is understandable under because it can be split into 4 words: what, is, your, name, and each word belongs to . The article whatisyouname is not understandable under , but it is understandable under . A prefix whatis of this article is also understandable under , and it is the longest prefix that can be understood under .
Given a dictionary , your program needs to determine whether several articles are understandable under , and output the position of the longest prefix that can be understood under .
Input Format
The first line contains two integers and , indicating that the dictionary has words and there are articles to process.
The next lines each contain a string , representing a word in the dictionary .
The next lines each contain a string , representing an article.
Output Format
For each article in the input, output one line with a single integer, the position of the longest prefix that can be understood under the dictionary .
4 3
is
name
what
your
whatisyourname
whatisyouname
whaisyourname
14
6
0
Hint
Explanation for Sample 1
- For the first query, the entire article
whatisyournamecan be understood. - For the second query, the prefix
whatiscan be understood. - For the third query, no prefix can be understood.
Constraints
- For of the data, it is guaranteed that , .
- For of the data, it is guaranteed that , , , , and both and contain only lowercase English letters.
Tips
- Pay attention to the impact of input reading on program efficiency.
- Note that the string lengths marked in Constraints are per-string lengths, not the sum of lengths.
Notes
- The testdata is strengthened; the first is the original testdata.
Translated by ChatGPT 5
京公网安备 11011102002149号