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 aa can be transformed into string bb.

Yousef has given you two binary strings, aa and bb, of the same length nn.

You are allowed to perform any of the following operations:

  • Choose a substring∗^{\text{∗}} in aa equal to 001\texttt{001} and replace it with 100\texttt{100}, or vice versa (i.e., 001→100\texttt{001} \rightarrow \texttt{100} or 100→001\texttt{100} \rightarrow \texttt {001}).
  • Choose a substring in aa equal to 110\texttt{110} and replace it with 011\texttt{011}, or vice versa (i.e., 011→110\texttt{011} \rightarrow \texttt{110} or 110→011\texttt{110} \rightarrow \texttt {011}).

Your task is to determine whether it is possible to transform string aa into string bb using a finite number of operations.

∗^{\text{∗}}A string aa is a substring of a string bb if aa can be obtained from bb by deletion of several (possibly zero or all) characters from the beginning and several (possibly zero or all) characters from the end.

这是该问题的简单版本。在此版本中,你只需判断字符串 aa 是否能被转换为字符串 bb。

Yousef 给你两个长度均为 nn 的二进制字符串 aa 和 bb。

你被允许执行以下任意操作:

  • 在 aa 中选择一个等于 001\texttt{001} 的子串,并将其替换为 100\texttt{100},或反之(即 001→100\texttt{001} \rightarrow \texttt{100} 或 100→001\texttt{100} \rightarrow \texttt{001})。
  • 在 aa 中选择一个等于 110\texttt{110} 的子串,并将其替换为 011\texttt{011},或反之(即 011→110\texttt{011} \rightarrow \texttt{110} 或 110→011\texttt{110} \rightarrow \texttt{011})。

你的任务是判断能否通过有限次操作将字符串 aa 转换为字符串 bb。

∗^{\text{∗}} 若字符串 aa 可通过从字符串 bb 的开头删除若干(可能为零个或全部)字符、并从结尾删除若干(可能为零个或全部)字符而得到,则称 aa 是 bb 的子串。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the length of each string.

The second line of each test case contains a binary string aa (∣a∣=n|a| = n), consisting of only characters 0\texttt{0} and/or 1\texttt{1}.

The third line of each test case contains a binary string bb (∣b∣=n|b| = n), consisting of only characters 0\texttt{0} and/or 1\texttt{1}.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 每个字符串的长度。

每个测试用例的第二行包含一个二进制字符串 aa(∣a∣=n|a| = n),仅由字符 0\texttt{0} 和/或 1\texttt{1} 组成。

每个测试用例的第三行包含一个二进制字符串 bb(∣b∣=n|b| = n),仅由字符 0\texttt{0} 和/或 1\texttt{1} 组成。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output "YES" if the string aa can be transformed into string bb 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.

对于每个测试用例,如果字符串 aa 可以通过有限次操作转换为字符串 bb,则输出 "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=ba = b. Therefore, the answer is YES.

In the second test case, we cannot perform any operation. Since a≠ba \neq b, the answer is NO.

In the third test case, we can choose the substring a[1,3]=001a[1, 3] = \texttt{001} and replace it with 100\texttt{100}, making a=ba = b. Therefore, the answer is YES.

In the seventh test case, we can do the following in order:

  • 1\texttt{1}100{\color{blue}{\texttt{100}}}00\texttt{00} →\rightarrow 1\texttt{1}001{\color{blue}{\texttt{001}}}00\texttt{00}
  • 100\texttt{100}100{\color{blue}{\texttt{100}}} →\rightarrow 100\texttt{100}001{\color{blue}{\texttt{001}}}
  • 100{\color{blue}{\texttt{100}}}001\texttt{001} →\rightarrow 001{\color{blue}{\texttt{001}}}001\texttt{001}
  • 00\texttt{00}100{\color{blue}{\texttt{100}}}1\texttt{1} →\rightarrow 00\texttt{00}001{\color{blue}{\texttt{001}}}1\texttt{1}

Therefore, the answer is YES.

在第一个测试用例中,已有 a=ba = b。因此,答案为 YES。

在第二个测试用例中,我们无法执行任何操作。由于 a≠ba \neq b,答案为 NO。

在第三个测试用例中,我们可以选择子串 a[1,3]=001a[1, 3] = \texttt{001} 并将其替换为 100\texttt{100},从而使 a=ba = b。因此,答案为 YES。

在第七个测试用例中,我们可以按以下顺序进行操作:

  • 1\texttt{1}100{\color{blue}{\texttt{100}}}00\texttt{00} →\rightarrow 1\texttt{1}001{\color{blue}{\texttt{001}}}00\texttt{00}
  • 100\texttt{100}100{\color{blue}{\texttt{100}}} →\rightarrow 100\texttt{100}001{\color{blue}{\texttt{001}}}
  • 100{\color{blue}{\texttt{100}}}001\texttt{001} →\rightarrow 001{\color{blue}{\texttt{001}}}001\texttt{001}
  • 00\texttt{00}100{\color{blue}{\texttt{100}}}1\texttt{1} →\rightarrow 00\texttt{00}001{\color{blue}{\texttt{001}}}1\texttt{1}

因此,答案为 YES。

输入解题思路,AI测评打分。不知道怎么写?

首页