CF2254C1.Marenol (easy version)
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is the easy version of the problem. In this version, you are only asked to determine whether string a can be transformed into string b.
Yousef has given you two binary strings, a and b, of the same length n.
You are allowed to perform any of the following operations:
- Choose a substring∗ in a equal to 001 and replace it with 100, or vice versa (i.e., 001→100 or 100→001).
- Choose a substring in a equal to 110 and replace it with 011, or vice versa (i.e., 011→110 or 110→011).
Your task is to determine whether it is possible to transform string a into string b using a finite number of operations.
∗A string a is a substring of a string b if a can be obtained from b by deletion of several (possibly zero or all) characters from the beginning and several (possibly zero or all) characters from the end.
这是该问题的简单版本。在此版本中,你只需判断字符串 a 是否能被转换为字符串 b。
Yousef 给你两个长度均为 n 的二进制字符串 a 和 b。
你被允许执行以下任意操作:
- 在 a 中选择一个等于 001 的子串,并将其替换为 100,或反之(即 001→100 或 100→001)。
- 在 a 中选择一个等于 110 的子串,并将其替换为 011,或反之(即 011→110 或 110→011)。
你的任务是判断能否通过有限次操作将字符串 a 转换为字符串 b。
∗ 若字符串 a 可通过从字符串 b 的开头删除若干(可能为零个或全部)字符、并从结尾删除若干(可能为零个或全部)字符而得到,则称 a 是 b 的子串。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains a single integer n (1≤n≤2⋅105) — the length of each string.
The second line of each test case contains a binary string a (∣a∣=n), consisting of only characters 0 and/or 1.
The third line of each test case contains a binary string b (∣b∣=n), consisting of only characters 0 and/or 1.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)—— 每个字符串的长度。
每个测试用例的第二行包含一个二进制字符串 a(∣a∣=n),仅由字符 0 和/或 1 组成。
每个测试用例的第三行包含一个二进制字符串 b(∣b∣=n),仅由字符 0 和/或 1 组成。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, output "YES" if the string a can be transformed into string b using a finite number of operations, and "NO" 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.
对于每个测试用例,如果字符串 a 可以通过有限次操作转换为字符串 b,则输出 "YES";否则输出 "NO"。
你可以以任意大小写形式输出答案(大写或小写均可)。例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均会被识别为肯定回答。
输入输出样例
输入#1
9 1 0 0 2 01 10 3 001 100 4 1010 0101 4 1100 1000 5 01001 10010 6 110000 000011 6 111000 000111 7 1001100 0000111
输出#1
YES NO YES NO NO YES YES NO YES
说明/提示
In the first test case, it already holds that a=b. Therefore, the answer is YES.
In the second test case, we cannot perform any operation. Since a=b, the answer is NO.
In the third test case, we can choose the substring a[1,3]=001 and replace it with 100, making a=b. Therefore, the answer is YES.
In the seventh test case, we can do the following in order:
- 110000 → 100100
- 100100 → 100001
- 100001 → 001001
- 001001 → 000011
Therefore, the answer is YES.
在第一个测试用例中,已有 a=b。因此,答案为 YES。
在第二个测试用例中,我们无法执行任何操作。由于 a=b,答案为 NO。
在第三个测试用例中,我们可以选择子串 a[1,3]=001 并将其替换为 100,从而使 a=b。因此,答案为 YES。
在第七个测试用例中,我们可以按以下顺序进行操作:
- 110000 → 100100
- 100100 → 100001
- 100001 → 001001
- 001001 → 000011
因此,答案为 YES。
输入解题思路,AI测评打分。不知道怎么写?