#P4022. [CTSC2012] 熟悉的文章

    ID: 2955 远端评测题 1000ms 250MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>字符串2012WC/CTSC/集训队后缀自动机,SAM

[CTSC2012] 熟悉的文章

Description

Amiba is Xiao Qiang’s good friend.

In Xiao Qiang’s eyes, Amiba is a literary youth with excellent essay scores. To grasp the essence of exam essays, Xiao Qiang asked Amiba for guidance. Amiba showed him several essays. Xiao Qiang felt they looked very familiar, as if they were pieced together from some model essays. He cast a doubtful look at Amiba, only to see a sly smile.

To convincingly show how “familiar” Amiba’s essays feel, Xiao Qiang devised a quantitative metric for the “degree of familiarity” of an essay: L0L_0. He first converts an essay into a 0101 string. Then he collects essays from various famous authors, also converts them into 0101 strings, and compiles a “standard essay library” containing MM 0101 strings.

Xiao Qiang considers the following: if a 0101 string has length at least LL and appears in some string in the standard essay library (i.e., it is a contiguous substring of some string in the library), then it is “familiar.” For an essay (a 0101 string) AA, if we can split AA into several substrings such that the total length of the “familiar” substrings is at least 90%90\% of the total length of AA, then AA is a “familiar article.” L0L_0 is the maximum among all LL that make AA a “familiar article” (if no such LL exists, define L0=0L_0 = 0).

For example:

Xiao Qiang’s essay library contains the following 22 strings:

10110
000001110

There is an essay to be examined:

1011001100

Xiao Qiang computes that the maximum LL for this essay is 44, because the essay can be viewed as 10110+0110+010110+0110+0, where 1011010110 and 01100110 are judged “familiar.” When L=5L = 5 or larger, no valid split exists. Therefore, this essay’s L0=4L_0 = 4. Xiao Qiang believes that Amiba’s L0L_0 values are noticeably larger than other students’. Please help him verify this.

Input Format

The first line contains two integers N,MN, M, denoting the number of essays to check and the number of strings in Xiao Qiang’s standard essay library.

The next MM lines contain 0101 strings, forming the standard essay library.

The next NN lines contain 0101 strings, representing the NN essays.

Output Format

Output NN lines. Each line contains one integer, the L0L_0 value of the corresponding essay.

1 2
10110
000001110
1011001100
4

Hint

For 30%30\% of the testdata, the input file length does not exceed 10001000 bytes.

For 50%50\% of the testdata, the input file length does not exceed 6100061000 bytes.

For 80%80\% of the testdata, the input file length does not exceed 250000250000 bytes.

For 100%100\% of the testdata, the input file length does not exceed 11000001100000 bytes.

Translated by ChatGPT 5