欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1704A.Two 0-1 Sequences
Two 0-1 Sequences
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.
Input
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 .
Output
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).
Note
In the first test case, you can use Operation 2 four times to make equals to .
In the second test case, you can use Operation 1 four times to make equals to .
In the third test case, it can be proved that no matter how we use the operations, it is impossible to make equal to .
In the fourth test case, it can be proved that no matter how we use the operations, it is impossible to make equal to .
In the fifth test case, you can use Operation 2 three times to make become , so the first element of equals to the first element of , but it can be proved that no matter how to operate, the second to the fifth elements of can't be the same as .
Samples
10
6 2
001001
11
6 2
110111
01
6 2
000001
11
6 2
111111
01
8 5
10000101
11010
7 4
1010001
1001
8 6
01010010
010010
8 4
01010101
1001
8 4
10101010
0110
7 5
1011100
11100
YES
YES
NO
NO
NO
YES
YES
NO
NO
YES
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |