「一本通 2.3 练习 2」L 语言
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
Description
Original source: HNOI 2004
The emergence of punctuation marks came later than that of written language, so ancient languages often lacked punctuation. Now, your task is to process an article without any punctuation.
An article consists of several lowercase letters. A word is also composed of several lowercase letters. A dictionary is a collection of several words. We say that an article can be understood under a dictionary if the article can be divided into several parts, where each part is a word in the dictionary .
For example, if dictionary includes the words is, your, what, and name, then the article whatisyourname can be understood under dictionary because it can be split into 4 words: what, is, your, name, and each word belongs to dictionary D. However, the article whatisyouname cannot be understood under dictionary , but it can be understood under dictionary you. A prefix of this article, whatis, can also be understood under dictionary D, and it is the longest prefix that can be understood under dictionary .
Given a dictionary , your program needs to determine whether several articles can be understood under dictionary . Additionally, you need to provide the position of the longest prefix of each article that can be understood under dictionary .
Input Format
The first line of the input file contains two positive integers and , indicating that dictionary has words and there are articles to be processed.
The following lines each describe a word, and the subsequent lines each describe an article.
Output Format
For each input article, you need to output the position of the longest prefix of the article that can be understood under dictionary .
Sample 1
For the article whatisyourname, the entire article whatisyourname can be understood.
For the article whatisyouname, the prefix whatis can be understood.
For the article whaisyourname, no prefix can be understood.
4 3
is
name
what
your
whatisyourname
whatisyouname
whaisyourname
14
6
0
Data Range and Hints
For of the data, , the length of each word does not exceed , and the length of each article does not exceed MB.
20251130 D班作业(8)
- Status
- Done
- Problem
- 4
- Open Since
- 2025-11-30 0:00
- Deadline
- 2025-12-15 23:59
- Extension
- 24 hour(s)