#abc324c. C - Error Correction

C - Error Correction

Score : 300300 points

问题描述

Takahashi 向 Aoki 发送了一个由小写英文字母组成的字符串 TT。结果,Aoki 收到的字符串为 TT',它同样由小写英文字母组成。

TT' 可能是从 TT 修改而来的。具体来说,已知恰好满足以下四个条件之一:

  • TT' 等于 TT
  • TT' 是在 TT 中的一个位置(可能是开头或结尾)插入一个英文字母后得到的字符串。
  • TT' 是从 TT 中删除一个字符后得到的字符串。
  • TT' 是通过将 TT 中的一个字符更改为另一个小写英文字母得到的字符串。

给定 Aoki 收到的字符串 TT' 以及由小写英文字母组成的 NN 个字符串 S1,S2,,SNS_1, S_2, \ldots, S_N。找出其中所有可能等于 Takahashi 发送的字符串 TTS1,S2,,SNS_1, S_2, \ldots, S_N 中的字符串。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Takahashi sent a string TT consisting of lowercase English letters to Aoki. As a result, Aoki received a string TT' consisting of lowercase English letters.

TT' may have been altered from TT. Specifically, exactly one of the following four conditions is known to hold.

  • TT' is equal to TT.
  • TT' is a string obtained by inserting one lowercase English letter at one position (possibly the beginning and end) in TT.
  • TT' is a string obtained by deleting one character from TT.
  • TT' is a string obtained by changing one character in TT to another lowercase English letter.

You are given the string TT' received by Aoki and NN strings S1,S2,,SNS_1, S_2, \ldots, S_N consisting of lowercase English letters. Find all the strings among S1,S2,,SNS_1, S_2, \ldots, S_N that could equal the string TT sent by Takahashi.

Constraints

  • NN is an integer.
  • 1N5×1051 \leq N \leq 5 \times 10^5
  • SiS_i and TT' are strings of length between 11 and 5×1055 \times 10^5, inclusive, consisting of lowercase English letters.
  • The total length of S1,S2,,SNS_1, S_2, \ldots, S_N is at most 5×1055 \times 10^5.

Input

The input is given from Standard Input in the following format:

NN TT'

S1S_1

S2S_2

\vdots

SNS_N

Output

Let (i1,i2,,iK)(i_1, i_2, \ldots, i_K) be the sequence of indices of all the strings among S1,S2,,SNS_1, S_2, \ldots, S_N that could be equal to TT, in ascending order. Print the length KK of this sequence, and the sequence itself, in the following format:

KK

i1i_1 i2i_2 \ldots iKi_K

Sample Input 1

5 ababc
ababc
babc
abacbc
abdbc
abbac

Sample Output 1

4
1 2 3 4

Among S1,S2,,S5S_1, S_2, \ldots, S_5, the strings that could be equal to TT are S1,S2,S3,S4S_1, S_2, S_3, S_4, as explained below.

  • S1S_1 could be equal to TT, because T=T' = ababc is equal to S1=S_1 = ababc.
  • S2S_2 could be equal to TT, because T=T' = ababc is obtained by inserting the letter a at the beginning of S2=S_2 = babc.
  • S3S_3 could be equal to TT, because T=T' = ababc is obtained by deleting the fourth character c from S3=S_3 = abacbc.
  • S4S_4 could be equal to TT, because T=T' = ababc is obtained by changing the third character d in S4=S_4 = abdbc to b.
  • S5S_5 could not be equal to TT, because if we take S5=S_5 = abbac as TT, then T=T' = ababc does not satisfy any of the four conditions in the problem statement.

Sample Input 2

1 aoki
takahashi

Sample Output 2

0

Sample Input 3

9 atcoder
atoder
atcode
athqcoder
atcoder
tacoder
jttcoder
atoder
atceoder
atcoer

Sample Output 3

6
1 2 4 7 8 9

update @ 2024/3/10 01:46:03