[Solution] Two 0-1 sequences Codeforces Solution
AquaMoon has two binary sequences and , which contain only and . AquaMoon can perform the following two operations any number of times ( is the first element of , is the second element of , and so on):
- Operation 1: if contains at least two elements, change to , and remove the first element of .
- Operation 2: if contains at least two elements, change to , and remove the first element of .
Note that after a removal of the first element of , the former becomes the first element of , the former becomes the second element of and so on, and the length of reduces by one.
Determine if AquaMoon can make equal to by using these operations.
The first line contains a single integer () — the number of test cases. Description of test cases follows.
The first line of each test case contains two integers , (, ) — the lengths of and respectively.
The second line of each test case contains a string of length , consisting only and .
The third line of each test case contains a string of length , consisting only and .
For each test case, output "YES" if AquaMoon can change to by using these options; otherwise, output "NO".
You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as a positive answer).
No comments:
Post a Comment