CF1451C.String Equality
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Ashish has two strings a and b, each of length n, and an integer k. The strings only contain lowercase English letters.
He wants to convert string a into string b by performing some (possibly zero) operations on a.
In one move, he can either
- choose an index i (1≤i≤n−1) and swap ai and ai+1, or
- choose an index i (1≤i≤n−k+1) and if ai,ai+1,…,ai+k−1 are all equal to some character c (c= 'z'), replace each one with the next character (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 a.
Help Ashish determine if it is possible to convert string a into b after performing some (possibly zero) operations on it.
阿什什有两个长度均为 n 的字符串 a 和 b,以及一个整数 k。这两个字符串仅由小写英文字母组成。
他希望通过在字符串 a 上执行若干次(可能为零次)操作,将 a 转换为 b。
每次操作可以是以下两种之一:
- 选择一个下标 i(1≤i≤n−1),交换 ai 与 ai+1;
- 选择一个下标 i(1≤i≤n−k+1),若子串 ai,ai+1,…,ai+k−1 中所有字符均等于某个字符 c(且 c=
'z'),则将这 k 个字符全部替换为下一个字符(即 c+1),例如'a'替换为'b','b'替换为'c',依此类推。
注意:他可以执行任意次数的操作,且所有操作只能作用于字符串 a。
请帮助阿什什判断:是否可以通过若干次(可能为零次)操作将字符串 a 转换为 b。
输入格式
The first line contains a single integer t (1≤t≤105) — the number of test cases. The description of each test case is as follows.
The first line of each test case contains two integers n (2≤n≤106) and k (1≤k≤n).
The second line of each test case contains the string a of length n consisting of lowercase English letters.
The third line of each test case contains the string b of length n consisting of lowercase English letters.
It is guaranteed that the sum of values n among all test cases does not exceed 106.
第一行包含一个整数 t(1≤t≤105),表示测试用例的数量。每个测试用例的描述如下:
每个测试用例的第一行包含两个整数 n(2≤n≤106)和 k(1≤k≤n)。
每个测试用例的第二行包含一个长度为 n 的字符串 a,由小写英文字母组成。
每个测试用例的第三行包含一个长度为 n 的字符串 b,由小写英文字母组成。
保证所有测试用例中 n 的总和不超过 106。
输出格式
For each test case, print "Yes" if Ashish can convert a into b after some moves, else print "No".
You may print the letters of the answer in any case (upper or lower).
对于每个测试用例,如果阿西什经过若干次操作后能将 a 转换为 b,则输出 "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 a into b.
In the second test case,
"abba" inc "acca" inc … 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 "aaabab" swap "aaaabb" inc … inc "ddaabb" inc … inc "ddddbb" inc … inc "ddddcc".
在第一个测试用例中,可以证明无法将 a 转换为 b。
在第二个测试用例中,
"abba" inc "acca" inc … inc "azza"。
其中,“swap”表示第一类操作,“inc”表示第二类操作。
在第四个测试用例中,
"aaabba" swap "aaabab" swap "aaaabb" inc … inc "ddaabb" inc … inc "ddddbb" inc … inc "ddddcc"。
输入解题思路,AI测评打分。不知道怎么写?