#P16827. [AFOI 2025] D.谐音替换
[AFOI 2025] D.谐音替换
Background
Time flies. That afternoon about “homophone replacement” is still clearly imprinted in little 's mind.
Back then, he insisted on exact matching: only completely identical substrings could be replaced. However, reality often did not go as hoped, and even tiny differences were enough to ruin all efforts.
Many years later, when little opened his linguistics notes again, he gained a new understanding of “homophones”: why demand complete equality? Having the same beginning or the same ending is already “homophonic” enough. Just like bits of memory, it does not need to be fully replayed; only a beginning or an ending is enough to connect the whole story.
Problem Description
Little is an algorithm contest participant who likes linguistics. In linguistics, homophone replacement means replacing original words with words that have the same or similar pronunciation. Little found that the process of homophone replacement can be described using prefix or suffix relationships of strings. Specifically, little defines homophone replacement as the following string problem:
- String is a homophone replacement of if and only if is a prefix of , or is a suffix of .
- Let the language set be . A homophone triple of string means splitting into three non-empty consecutive parts (where denotes string concatenation), such that each part is a homophone replacement of some string in . Each splitting corresponds to one string triple , and we call this triple a homophone triple of string . Two homophone triples and are essentially different if and only if or or .
Now you are given strings as the language set, and strings as the language materials to be analyzed.
For each , please help little find how many essentially different homophone triple schemes there are.
Input Format
The first line contains two integers and ().
The next lines each contain a string , representing a word in the language set.
The next lines each contain a string , representing the material to be analyzed.
Output Format
Output lines. The -th line () contains a non-negative integer, indicating how many essentially different homophone triples has.
1 1
abbcabb
abbcabbcabb
12
Hint
Sample 1 Explanation
The essentially different homophone triples are as follows:
Constraints
Let be the length of string , , and . For all testdata, it is guaranteed that:
- ;
- , ;
- , ;
- For all , each contains only uppercase and lowercase English letters.
- For all , each contains only uppercase and lowercase English letters.
| Test Point ID | Special Property | |||
|---|---|---|---|---|
| None | ||||
| ^ | ||||
| ^ | A, B | |||
| ^ | A | |||
| B | ||||
| ^ | None | |||
| A | ||||
| ^ | B | |||
| None | ||||
Special property A: .
Special property B: For all , each ends with z. For all , each does not contain z.
Translated by ChatGPT 5