#P17581. [JAG 2026 Summer Camp #3] Forbidden Word

    ID: 20289 远端评测题 3000ms 2048MiB 尝试: 0 已通过: 0 显示难度提高+/省选− 上传者: 标签>哈希 hashingKMP 算法ICPC2026bitset

[JAG 2026 Summer Camp #3] Forbidden Word

Problem Description

You are a highly skilled programmer working in the social media monitoring division of ICPC (International Company of Public Communication), a giant corporation. Your task is to write a program that determines whether a message scheduled to be posted on social media by the public relations department contains a predefined forbidden word.

In recent years, numerous social media controversies have been caused by unintended hidden messages that appear when a post is wrapped at a particular number of characters and the characters in each column are read vertically. Forbidden words that appear horizontally within a displayed row must also be avoided.

For example, consider the forbidden word dk and the message abcdefghijklmn. When the viewer's screen width is 1010 characters, the message is displayed as shown in Figure J-1, and dk does not appear when the columns are read vertically. However, when the screen width is 77 characters, the message is displayed as shown in Figure J-2, and reading the fourth column from top to bottom yields dk.

abcdefghij
klmn

Figure J-1: Screen width 10.

abcdefg
hijklmn

Figure J-2: Screen width 7.

You are given a string SS of length NN, representing the message to be posted, and a string TT of length MM, representing the forbidden word. Because social media users may view the message on screens of various widths, you must determine whether the message is at risk of causing a controversy for each possible screen width ii (1≤i≤N1\le i\le N).

For a screen width of ii, the string SS is displayed with a line break after every ii characters, starting from the beginning of the string. More precisely, the jj-th character of SS (1≤j≤N1\le j\le N) is placed in row ⌊(j−1)/i⌋+1\lfloor(j-1)/i\rfloor+1 from the top and column ((j−1) mod i)+1((j-1)\bmod i)+1 from the left. Note that the last row may contain fewer than ii characters.

For a screen width of ii, the message is considered at risk of causing a controversy if TT occurs as a contiguous substring in the left-to-right reading of some row or in the top-to-bottom reading of some column.

Input Format

The input contains one or more test cases. The first line of the input contains an integer tt (1≤t≤1001\le t\le100), which is the number of test cases. The descriptions of the tt test cases follow, each in the following format.

N M
S
T

The first line of each test case contains two integers NN and MM (1≤M≤N≤2×1051\le M\le N\le2\times10^5), representing the lengths of the message and the forbidden word, respectively. The second line contains a string SS of length NN consisting of lowercase English letters. The third line contains a string TT of length MM consisting of lowercase English letters.

The sum of NN over all test cases does not exceed 2×1052\times10^5, and the sum of MM over all test cases does not exceed 2×1052\times10^5.

Output Format

For each test case, output a binary string of length NN. For each ii (1≤i≤N1\le i\le N), the ii-th character of the string should be 1 if the message is at risk of causing a controversy for a screen width of ii, and 0 otherwise.

5
14 2
abcdefghijklmn
dk
6 3
banana
ana
10 2
ababababab
aa
11 4
mississippi
issi
8 3
aaaaaaaa
aaa
00000010000000
101111
0101010100
11011111111
11111111