欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1861B.Two Binary Strings
Two Binary Strings
You are given two strings and of equal length, consisting of only characters 0 and/or 1; both strings start with character 0 and end with character 1.
You can perform the following operation any number of times (possibly zero):
- choose one of the strings and two equal characters in it; then turn all characters between them into those characters.
Formally, you choose one of these two strings (let the chosen string be ), then pick two integers and such that and , then replace every character such that with .
For example, if the chosen string is 010101, you can transform it into one of the following strings by applying one operation:
000101if you choose and ;000001if you choose and ;010001if you choose and ;010111if you choose and ;011111if you choose and ;011101if you choose and .
You have to determine if it's possible to make the given strings equal by applying this operation any number of times.
Input
The first line contains a single integer () — the number of test cases.
Each test case consists of two lines:
- the first line contains the string (), consisting of only characters
0and/or1. - the second line contains the string (), consisting of only characters
0and/or1.
Additional constraints on the input:
- in each test case, (the strings have equal length);
- in each test case, both strings start with
0and end with1; - the total length of all strings in all test cases does not exceed .
Output
For each test case, print YES if it is possible to make the strings equal. Otherwise, print NO. You can print each letter in any register.
Note
In the first test case, we can perform the following operations:
- choose the string , , ; after this operation, is
01110001, is01110101; - choose the string , , ; after this operation, is
01110001, is01110001.
In the second test case, the strings are already equal.
In the third test case, we can perform the following operations:
- choose the string , , ; after this operation, is
000111, is010111; - choose the string , , ; after this operation, is
000111, is000111;
In the fourth and fifth test cases, it's impossible to make the given strings equal.
Samples
7
01010001
01110101
01001
01001
000101
010111
00001
01111
011
001
001001
011011
010001
011011
YES
YES
YES
NO
NO
NO
YES
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |