CF1890B.Qingshan Loves Strings

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Qingshan has a string ss, while Daniel has a string tt. Both strings only contain 0\texttt{0} and 1\texttt{1}.

A string aa of length kk is good if and only if

  • ai≠ai+1a_i \ne a_{i+1} for all i=1,2,…,k−1i=1,2,\ldots,k-1.

For example, 1\texttt{1}, 101\texttt{101}, 0101\texttt{0101} are good, while 11\texttt{11}, 1001\texttt{1001}, 001100\texttt{001100} are not good.

Qingshan wants to make ss good. To do this, she can do the following operation any number of times (possibly, zero):

  • insert tt to any position of ss (getting a new ss).

Please tell Qingshan if it is possible to make ss good.

青衫有一字符串 ss,而丹尼尔有一字符串 tt。两个字符串仅由字符 0\texttt{0} 和 1\texttt{1} 组成。

长度为 kk 的字符串 aa 被称为好串,当且仅当

  • 对所有 i=1,2,…,k−1i=1,2,\ldots,k-1,均有 ai≠ai+1a_i \ne a_{i+1}。

例如,1\texttt{1}、101\texttt{101}、0101\texttt{0101} 是好串,而 11\texttt{11}、1001\texttt{1001}、001100\texttt{001100} 不是好串。

青衫希望将 ss 变为好串。为此,她可以执行以下操作任意多次(包括零次):

  • 将 tt 插入到 ss 的任意位置(从而得到一个新的 ss)。

请告诉青衫:是否可能通过上述操作使 ss 成为好串?

输入格式

The input consists of multiple test cases. The first line contains a single integer TT (1≤T≤20001\le T\le 2000) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers nn and mm (1≤n,m≤501 \le n,m \le 50) — the length of the strings ss and tt, respectively.

The second line of each test case contains a string ss of length nn.

The third line of each test case contains a string tt of length mm.

It is guaranteed that ss and tt only contain 0\texttt{0} and 1\texttt{1}.

输入包含多个测试用例。第一行包含一个整数 TT(1≤T≤20001\le T\le 2000),表示测试用例的数量。随后是各测试用例的描述。

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

每个测试用例的第二行包含一个长度为 nn 的字符串 ss。

每个测试用例的第三行包含一个长度为 mm 的字符串 tt。

保证 ss 和 tt 仅由字符 0\texttt{0} 和 1\texttt{1} 组成。

输出格式

For each test case, print "YES" (without quotes), if it is possible to make ss good, and "NO" (without quotes) otherwise.

You can print letters in any case (upper or lower).

对于每个测试用例,如果可以将 ss 变为“好串”,则输出 "YES"(不带引号);否则输出 "NO"(不带引号)。

你可以以任意大小写形式输出字母(大写或小写)。

输入输出样例

  • 输入#1

    5
    1 1
    1
    0
    3 3
    111
    010
    3 2
    111
    00
    6 7
    101100
    1010101
    10 2
    1001001000
    10

    输出#1

    Yes
    Yes
    No
    No
    No

说明/提示

In the first test case, ss is good initially, so you can get a good ss by doing zero operations.

In the second test case, you can do the following two operations (the inserted string tt is underlined):

  1. 1010‾11\texttt{1}\underline{\texttt{010}}\texttt{11}
  2. 10101010‾1\texttt{10101}\underline{\texttt{010}}\texttt{1}

and get s=101010101s = \texttt{101010101}, which is good.

In the third test case, there is no way to make ss good after any number of operations.

在第一个测试用例中,ss 初始即为“好”的,因此你可以通过执行零次操作得到一个“好”的 ss。

在第二个测试用例中,你可以执行以下两次操作(插入的字符串 tt 用下划线标出):

  1. 1010‾11\texttt{1}\underline{\texttt{010}}\texttt{11}
  2. 10101010‾1\texttt{10101}\underline{\texttt{010}}\texttt{1}

从而得到 s=101010101s = \texttt{101010101},该字符串是“好”的。

在第三个测试用例中,无论执行多少次操作,都无法使 ss 变为“好”的。

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

首页