#P11016. [2016杭电多校]La Vie en rose
[2016杭电多校]La Vie en rose
La Vie en rose
Problem Description
Professor Zhang would like to solve the multiple pattern matching problem, but he only has only one pattern string . So, he wants to generate as many as possible pattern strings from using the following method:
- select some indices such that and for all .
- swap and for all . Now, for a given a string , Professor Zhang wants to find all occurrences of all the generated patterns in .
Input
There are multiple test cases. The first line of input contains an integer , indicating the number of test cases. For each test case: The first line contains two integers and -- the length of and . The second line contains the string and the third line contains the string . Both the strings consist of only lowercase English letters.
Output
For each test case, output a binary string of length . The -th character is "1" if and only if the substring is one of the generated patterns.
Sample Input
3
4 1
abac
a
4 2
aaaa
aa
9 3
abcbacacb
abc
Sample Output
1010
1110
100100100
Author
zimpha
Source
2016 Multi-University Training Contest 2