CF1898E.Sofia and Strings

普及/提高-

通过率:0%

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 1is1 \le i \le |s| and remove the character sis_i from the string.
  2. Select a pair of indices (l,r)(l, r) ( 1lrs1 \le l \le r \le |s| ) and sort the substring slsl+1srs_{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.

输入格式

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

The first line of each test case contains two integers nn , mm ( 1mn21051\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 21052\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.

输入输出样例

  • 输入#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.

首页