CF1898E.Sofia and Strings

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Sofia has a string ss of length nn, consisting only of lowercase English letters. She can perform operations of the following types with this string.

  1. Select an index 1≤i≤∣s∣1 \le i \le |s| and remove the character sis_i from the string.
  2. Select a pair of indices (l,r)(l, r) (1≤l≤r≤∣s∣1 \le l \le r \le |s|) and sort the substring slsl+1…srs_{l} s_{l+1} \ldots s_r in alphabetical order.

Here, ∣s∣|s| denotes the current length of ss. In particular, ∣s∣=n|s| = n before the first operation. For example, if s=sofias = \mathtt{sofia}, then performing the operation of the first type with i=4i=4 results in ss becoming sofa\mathtt{sofa}, and performing the operation of the second type with (l,r)=(2,4)(l, r) = (2, 4) after that results in ss becoming safo\mathtt{safo}.

Sofia wants to obtain the string tt of length mm after performing zero or more operations on string ss as described above. Please determine whether it is possible or not.

索菲亚有一个长度为 nn 的字符串 ss,其中仅包含小写英文字母。她可以对这个字符串执行以下两类操作:

  1. 选择一个下标 1≤i≤∣s∣1 \le i \le |s|,从字符串中删除字符 sis_i;
  2. 选择一对下标 (l,r)(l, r)(满足 1≤l≤r≤∣s∣1 \le l \le r \le |s|),将子串 slsl+1…srs_{l} s_{l+1} \ldots s_r 按字母顺序升序排序。

此处,∣s∣|s| 表示字符串 ss 的当前长度;特别地,在第一次操作前有 ∣s∣=n|s| = n。例如,若 s=sofias = \mathtt{sofia},则执行第一类操作并取 i=4i=4 后,ss 变为 sofa\mathtt{sofa};再在此基础上执行第二类操作并取 (l,r)=(2,4)(l, r) = (2, 4),则 ss 变为 safo\mathtt{safo}。

索菲亚希望通过对字符串 ss 执行零次或多次上述操作,最终得到长度为 mm 的字符串 tt。请判断该目标是否可达。

输入格式

The first line contains one integer tt (1≤t≤10 0001 \leq t \leq 10\,000) — the number of test cases.

The first line of each test case contains two integers nn, mm (1≤m≤n≤2⋅1051\leq m \leq n \leq 2\cdot 10^5) — the lengths of string ss and tt, respectively.

The second line of each test case contains the string ss of length nn, consisting only of lowercase English letters.

The third line of each test case contains the string tt of length mm, consisting only of lowercase English letters.

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

第一行包含一个整数 tt(1≤t≤10 0001 \leq t \leq 10\,000)—— 表示测试用例的数量。

每个测试用例的第一行包含两个整数 nn、mm(1≤m≤n≤2⋅1051\leq m \leq n \leq 2\cdot 10^5)—— 分别表示字符串 ss 和 tt 的长度。

每个测试用例的第二行包含一个长度为 nn 的字符串 ss,仅由小写英文字母组成。

每个测试用例的第三行包含一个长度为 mm 的字符串 tt,仅由小写英文字母组成。

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

输出格式

For each test case, output "YES" if Sofia can obtain the string tt from ss using the operations above. Otherwise, output "NO".

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.

对于每个测试用例,如果索菲亚能通过上述操作从字符串 ss 得到字符串 tt,则输出 "YES";否则输出 "NO"。

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

输入输出样例

  • 输入#1

    8
    5 5
    sofia
    afios
    3 2
    cba
    bc
    5 1
    sofia
    e
    15 7
    anavolimilovana
    aamanan
    26 4
    abcdefghijklmnopqrstuvwxyz
    nope
    26 4
    zyxwvutsrqponmlkjihgfedcba
    nope
    7 3
    apricot
    cat
    3 3
    cba
    acb

    输出#1

    YES
    YES
    NO
    YES
    NO
    YES
    NO
    YES

说明/提示

In the first test case, Sofia can perform the following operation:

  1. operation of the second type with l=1l=1 and r=5r=5: string ss becomes afios\mathtt{afios} after it.

In the second test case, Sofia can perform the following operations:

  1. operation of the second type with l=1l=1 and r=2r=2: string ss becomes bca\mathtt{bca} after it;
  2. operation of the first type with i=3i=3: string ss becomes bc\mathtt{bc} after it.

In the third test case, it can be shown that it is impossible to obtain tt from ss using the provided operations.

在第一个测试用例中,索菲亚可以执行以下操作:

  1. 执行第二种类型的操作,其中 l=1l=1 且 r=5r=5:字符串 ss 将变为 afios\mathtt{afios}。

在第二个测试用例中,索菲亚可以执行以下操作:

  1. 执行第二种类型的操作,其中 l=1l=1 且 r=2r=2:字符串 ss 将变为 bca\mathtt{bca};
  2. 执行第一种类型的操作,其中 i=3i=3:字符串 ss 将变为 bc\mathtt{bc}。

在第三个测试用例中,可以证明:无法通过给定的操作将 ss 变为 tt。

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

首页