#P4173. 残缺的字符串

    ID: 3085 远端评测题 2000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>字符串数学KMP快速傅里叶变换 FFT

残缺的字符串

Description

Long ago, when you had just learned string matching, there were two strings AA and BB containing only lowercase letters, with lengths mm and nn respectively. Now, when you encounter these two strings again, they have aged; each string has become partially damaged.

You want to match the two strings again, taking AA as the pattern. For every position ii in BB, determine whether the length-mm substring starting at this position could exactly match string AA.

Input Format

The first line contains two positive integers m,nm, n, representing the lengths of strings AA and BB respectively.

The second line contains a string AA of length mm.

The third line contains a string BB of length nn.

Both strings consist only of lowercase letters and *\texttt *, where *\texttt * indicates that the corresponding position is damaged and each *\texttt * can match any single lowercase letter.

Output Format

The first line contains an integer kk, the number of starting positions in BB where AA can exactly match.

If k>0k > 0, then on the second line output kk positive integers in increasing order, each being a valid starting position (indices start from 11).

3 7
a*b
aebr*ob
2
1 5

Hint

For 100%100\% of the testdata, 1mn3×1051 \le m \le n \le 3 \times 10^5.

Translated by ChatGPT 5