欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2029B.Replacement
Replacement
You have a binary string of length , and Iris gives you another binary string of length .
Iris is going to play a game with you. During the game, you will perform operations on . In the -th operation ():
- First, you choose an index such that and . If it is impossible to choose such an index, you lose;
- Then, you replace with . Note that this decreases the length of by .
If all the operations are performed successfully, you win.
Determine whether it is possible for you to win this game.
A binary string is a string where each character is either 0 or 1.
Input
Each test contains multiple test cases. The first line of the input contains a single integer () — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer () — the length of .
The second line contains the binary string of length ( or 1).
The third line contains the binary string of length ( or 1).
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, print "YES" (without quotes) if you can win the game, and "NO" (without quotes) otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
Note
In the first test case, you cannot perform the first operation. Thus, you lose the game.
In the second test case, you can choose in the only operation, and after that, becomes equal to 1. Thus, you win the game.
In the third test case, you can perform the following operations: 1}\underline{\mathtt{10}}\mathtt{1}\xrightarrow{r_1=\mathtt{0}} \mathtt{1}\underline{\mathtt{01}} \xrightarrow{r_2=\mathtt{0}} \underline{\mathtt{10}} \xrightarrow{r_3=\mathtt{1}} \mathtt{1.
Samples
6
2
11
0
2
01
1
4
1101
001
6
111110
10000
6
010010
11010
8
10010010
0010010
NO
YES
YES
NO
YES
NO
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |