D. 「一本通 2.3 练习 2」L 语言

    Type: Default 1000ms 512MiB

「一本通 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 TT consists of several lowercase letters. A word WW is also composed of several lowercase letters. A dictionary DD is a collection of several words. We say that an article TT can be understood under a dictionary DD if the article TT can be divided into several parts, where each part is a word in the dictionary DD.

For example, if dictionary DD includes the words is, your, what, and name, then the article whatisyourname can be understood under dictionary DD 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 DD, but it can be understood under dictionary D=D+D’=D+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 DD.

Given a dictionary DD, your program needs to determine whether several articles can be understood under dictionary DD. Additionally, you need to provide the position of the longest prefix of each article that can be understood under dictionary DD.

Input Format

The first line of the input file contains two positive integers nn and mm, indicating that dictionary DD has nn words and there are mm articles to be processed.

The following nn lines each describe a word, and the subsequent mm 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 DD.

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 100%100\% of the data, 1n,m201\le n, m\le 20, the length of each word does not exceed 1010, and the length of each article does not exceed 11 MB.

20251130 D班作业(8)

Not Claimed
Status
Done
Problem
4
Open Since
2025-11-30 0:00
Deadline
2025-12-15 23:59
Extension
24 hour(s)