#P11412. [EPXLQ2024 fall round] 风吹起了从前
[EPXLQ2024 fall round] 风吹起了从前
Background
About the past, Wen Zhaoxue has fragmented memories.
Problem Description
Specifically, she has memories. Each memory is a string of length at most . The -th memory lies at depth in her mind and has value to her.
Wen Zhaoxue is trying to recover the beauty in her memories, but there are simply too many and they are too complex. She can only think of a prefix segment of her memories and the deepest position she can reach. Only memories that satisfy: the corresponding is a prefix of and , can be recalled by Wen Zhaoxue.
Now, Wen Zhaoxue makes attempts. She wants to know, for each attempt, what the sum of values of all memories she can obtain is.
Input Format
The first line contains .
The next lines each contain two integers and a string , separated by spaces.
The next lines each contain an integer and a string , separated by spaces. It is guaranteed that is a prefix of at least one , but it is not guaranteed that there exists a memory that can actually be recalled.
Output Format
Output lines. Each line represents, for each attempt, the sum of values of all memories she can obtain.
5 6
5 6 abcab
7 10 abcba
4 3 abc
3 6 ade
2 4 cde
2 abc
4 abc
5 abc
6 a
7 c
8 ab
0
3
9
15
4
19
Hint
Hint
In this problem, the definition of a prefix is as follows: for strings , if and for all we have , then is called a prefix of .
Scale and Constraints
This problem uses bundled testdata.
| Special property | Score | |||
|---|---|---|---|---|
| String length is at most | ||||
For all testdata, it is guaranteed that , , and all strings consist only of lowercase letters.
Please pay attention to the impact of constant factors in time complexity.
Please consider using faster input/output methods.
Translated by ChatGPT 5