CF1704A.Two 0-1 Sequences

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

AquaMoon has two binary sequences aa and bb, which contain only 00 and 11. AquaMoon can perform the following two operations any number of times (a1a_1 is the first element of aa, a2a_2 is the second element of aa, and so on):

  • Operation 1: if aa contains at least two elements, change a2a_2 to min⁡(a1,a2)\operatorname{min}(a_1,a_2), and remove the first element of aa.
  • Operation 2: if aa contains at least two elements, change a2a_2 to max⁡(a1,a2)\operatorname{max}(a_1,a_2), and remove the first element of aa.

Note that after a removal of the first element of aa, the former a2a_2 becomes the first element of aa, the former a3a_3 becomes the second element of aa and so on, and the length of aa reduces by one.

Determine if AquaMoon can make aa equal to bb by using these operations.

AquaMoon 有两个仅包含 00 和 11 的二进制序列 aa 和 bb。AquaMoon 可以任意次执行以下两种操作(其中 a1a_1 表示 aa 的第一个元素,a2a_2 表示 aa 的第二个元素,依此类推):

  • 操作 1:若 aa 至少包含两个元素,则将 a2a_2 修改为 min⁡(a1,a2)\operatorname{min}(a_1,a_2),并删除 aa 的第一个元素。
  • 操作 2:若 aa 至少包含两个元素,则将 a2a_2 修改为 max⁡(a1,a2)\operatorname{max}(a_1,a_2),并删除 aa 的第一个元素。

注意:在删除 aa 的第一个元素后,原来的 a2a_2 成为 aa 的第一个元素,原来的 a3a_3 成为 aa 的第二个元素,依此类推;且 aa 的长度减小 11。

判断 AquaMoon 能否通过执行上述操作使 aa 变为 bb。

输入格式

The first line contains a single integer tt (1≤t≤2 0001 \leq t \leq 2\,000) — the number of test cases. Description of test cases follows.

The first line of each test case contains two integers nn, mm (1≤n,m≤501 \leq n,m \leq 50, m≤nm \leq n) — the lengths of aa and bb respectively.

The second line of each test case contains a string aa of length nn, consisting only 00 and 11.

The third line of each test case contains a string bb of length mm, consisting only 00 and 11.

第一行包含一个整数 tt(1≤t≤2 0001 \leq t \leq 2\,000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n,m≤501 \leq n,m \leq 50,且 m≤nm \leq n),分别表示字符串 aa 和 bb 的长度。

每个测试用例的第二行包含一个长度为 nn 的字符串 aa,仅由字符 00 和 11 组成。

每个测试用例的第三行包含一个长度为 mm 的字符串 bb,仅由字符 00 和 11 组成。

输出格式

For each test case, output "YES" if AquaMoon can change aa to bb 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).

对于每个测试用例,如果 AquaMoon 能够通过使用这些选项将 aa 变为 bb,则输出 "YES";否则输出 "NO"。

你可以以任意大小写形式输出每个字母(例如,"YES"、"Yes"、"yes"、"yEs" 均会被识别为肯定回答)。

输入输出样例

  • 输入#1

    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

    输出#1

    YES
    YES
    NO
    NO
    NO
    YES
    YES
    NO
    NO
    YES

说明/提示

In the first test case, you can use Operation 2 four times to make aa equals to bb.

In the second test case, you can use Operation 1 four times to make aa equals to bb.

In the third test case, it can be proved that no matter how we use the operations, it is impossible to make aa equal to bb.

In the fourth test case, it can be proved that no matter how we use the operations, it is impossible to make aa equal to bb.

In the fifth test case, you can use Operation 2 three times to make aa become 1010110101, so the first element of aa equals to the first element of bb, but it can be proved that no matter how to operate, the second to the fifth elements of aa can't be the same as bb.

在第一个测试用例中,你可以使用操作 2 四次,使 aa 等于 bb。

在第二个测试用例中,你可以使用操作 1 四次,使 aa 等于 bb。

在第三个测试用例中,可以证明:无论怎样使用这些操作,都无法使 aa 等于 bb。

在第四个测试用例中,可以证明:无论怎样使用这些操作,都无法使 aa 等于 bb。

在第五个测试用例中,你可以使用操作 2 三次,使 aa 变为 1010110101,因此 aa 的第一个元素等于 bb 的第一个元素;但可以证明:无论怎样操作,aa 的第二至第五个元素都无法与 bb 对应位置的元素相同。

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

首页