CF1451C.String Equality

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Ashish has two strings aa and bb, each of length nn, and an integer kk. The strings only contain lowercase English letters.

He wants to convert string aa into string bb by performing some (possibly zero) operations on aa.

In one move, he can either

  • choose an index ii (1≤i≤n−11 \leq i\leq n-1) and swap aia_i and ai+1a_{i+1}, or
  • choose an index ii (1≤i≤n−k+11 \leq i \leq n-k+1) and if ai,ai+1,…,ai+k−1a_i, a_{i+1}, \ldots, a_{i+k-1} are all equal to some character cc (c≠c \neq 'z'), replace each one with the next character (c+1)(c+1), that is, 'a' is replaced by 'b', 'b' is replaced by 'c' and so on.

Note that he can perform any number of operations, and the operations can only be performed on string aa.

Help Ashish determine if it is possible to convert string aa into bb after performing some (possibly zero) operations on it.

阿什什有两个长度均为 nn 的字符串 aa 和 bb,以及一个整数 kk。这两个字符串仅由小写英文字母组成。

他希望通过在字符串 aa 上执行若干次(可能为零次)操作,将 aa 转换为 bb。

每次操作可以是以下两种之一:

  • 选择一个下标 ii(1≤i≤n−11 \leq i \leq n-1),交换 aia_i 与 ai+1a_{i+1};
  • 选择一个下标 ii(1≤i≤n−k+11 \leq i \leq n-k+1),若子串 ai,ai+1,…,ai+k−1a_i, a_{i+1}, \ldots, a_{i+k-1} 中所有字符均等于某个字符 cc(且 c≠c \neq 'z'),则将这 kk 个字符全部替换为下一个字符(即 c+1c+1),例如 'a' 替换为 'b','b' 替换为 'c',依此类推。

注意:他可以执行任意次数的操作,且所有操作只能作用于字符串 aa。

请帮助阿什什判断:是否可以通过若干次(可能为零次)操作将字符串 aa 转换为 bb。

输入格式

The first line contains a single integer tt (1≤t≤1051 \leq t \leq 10^5) — the number of test cases. The description of each test case is as follows.

The first line of each test case contains two integers nn (2≤n≤1062 \leq n \leq 10^6) and kk (1≤k≤n1 \leq k \leq n).

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

The third line of each test case contains the string bb of length nn consisting of lowercase English letters.

It is guaranteed that the sum of values nn among all test cases does not exceed 10610^6.

第一行包含一个整数 tt(1≤t≤1051 \leq t \leq 10^5),表示测试用例的数量。每个测试用例的描述如下:

每个测试用例的第一行包含两个整数 nn(2≤n≤1062 \leq n \leq 10^6)和 kk(1≤k≤n1 \leq k \leq n)。

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

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

保证所有测试用例中 nn 的总和不超过 10610^6。

输出格式

For each test case, print "Yes" if Ashish can convert aa into bb after some moves, else print "No".

You may print the letters of the answer in any case (upper or lower).

对于每个测试用例,如果阿西什经过若干次操作后能将 aa 转换为 bb,则输出 "Yes";否则输出 "No"。

你可以以任意大小写(大写或小写)输出答案的字母。

输入输出样例

  • 输入#1

    4
    3 3
    abc
    bcd
    4 2
    abba
    azza
    2 1
    zz
    aa
    6 2
    aaabba
    ddddcc

    输出#1

    No
    Yes
    No
    Yes

说明/提示

In the first test case it can be shown that it is impossible to convert aa into bb.

In the second test case,

"abba" →inc\xrightarrow{\text{inc}} "acca" →inc\xrightarrow{\text{inc}} …\ldots →inc\xrightarrow{\text{inc}} "azza".

Here "swap" denotes an operation of the first type, and "inc" denotes an operation of the second type.

In the fourth test case,

"aaabba" →swap\xrightarrow{\text{swap}} "aaabab" →swap\xrightarrow{\text{swap}} "aaaabb" →inc\xrightarrow{\text{inc}} …\ldots →inc\xrightarrow{\text{inc}} "ddaabb" →inc\xrightarrow{\text{inc}} …\ldots →inc\xrightarrow{\text{inc}} "ddddbb" →inc\xrightarrow{\text{inc}} …\ldots →inc\xrightarrow{\text{inc}} "ddddcc".

在第一个测试用例中,可以证明无法将 aa 转换为 bb。

在第二个测试用例中,

"abba" →inc\xrightarrow{\text{inc}} "acca" →inc\xrightarrow{\text{inc}} …\ldots →inc\xrightarrow{\text{inc}} "azza"。

其中,“swap”表示第一类操作,“inc”表示第二类操作。

在第四个测试用例中,

"aaabba" →swap\xrightarrow{\text{swap}} "aaabab" →swap\xrightarrow{\text{swap}} "aaaabb" →inc\xrightarrow{\text{inc}} …\ldots →inc\xrightarrow{\text{inc}} "ddaabb" →inc\xrightarrow{\text{inc}} …\ldots →inc\xrightarrow{\text{inc}} "ddddbb" →inc\xrightarrow{\text{inc}} …\ldots →inc\xrightarrow{\text{inc}} "ddddcc"。

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

首页