310212: CF1800E1. Unforgivable Curse (easy version)

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Unforgivable Curse (easy version)

题意翻译

与 E2 的差异仅在 $k$ 的取值不同。 给定两个长度为 $n$ 的字符串 $s_1,s_2$ 以及一个正整数 $k$,你可以进行任意次操作(可以不操作): 若 $|i-j|=k$ 或 $|i-j|=k+1$,交换 $s_2$ 第 $i$ 个位置的字符与第 $j$ 个位置的字符。 问最终能否使得 $s_1,s_2$ 完全相同。 本题有多组测试数据。 $1\leq T\leq 10^4,1\leq n\leq 2\times 10^5,k=3,\sum n\leq 2\times 10^5$ translated by @[StayAlone](https://www.luogu.com.cn/user/409236)

题目描述

This is an easy version of the problem. In this version, $ k $ is always $ 3 $ . The chief wizard of the Wizengamot once caught the evil wizard Drahyrt, but the evil wizard has returned and wants revenge on the chief wizard. So he stole spell $ s $ from his student Harry. The spell — is a $ n $ -length string of lowercase Latin letters. Drahyrt wants to replace spell with an unforgivable curse — string $ t $ . Drahyrt, using ancient magic, can swap letters at a distance $ k $ or $ k+1 $ in spell as many times as he wants. In this version of the problem, you can swap letters at a distance of $ 3 $ or $ 4 $ . In other words, Drahyrt can change letters in positions $ i $ and $ j $ in spell $ s $ if $ |i-j|=3 $ or $ |i-j|=4 $ . For example, if $ s = $ "talant" and $ t = $ "atltna", Drahyrt can act as follows: - swap the letters at positions $ 1 $ and $ 4 $ to get spell "aaltnt". - swap the letters at positions $ 2 $ and $ 6 $ to get spell "atltna". You are given spells $ s $ and $ t $ . Can Drahyrt change spell $ s $ to $ t $ ?

输入输出格式

输入格式


The first line of input gives a single integer $ T $ ( $ 1 \le T \le 10^4 $ ) — the number of test cases in the test. Descriptions of the test cases are follow. The first line contains two integers $ n, k $ ( $ 1 \le n \le 2 \cdot 10^5 $ , $ k = 3 $ ) — the length spells and the number $ k $ such that Drahyrt can change letters in a spell at a distance $ k $ or $ k+1 $ . The second line gives spell $ s $ — a string of length $ n $ consisting of lowercase Latin letters. The third line gives spell $ t $ — a string of length $ n $ consisting of lowercase Latin letters. It is guaranteed that the sum of $ n $ values over all test cases does not exceed $ 2 \cdot 10^5 $ . Note that there is no limit on the sum of $ k $ values over all test cases.

输出格式


For each test case, output on a separate line "YES" if Drahyrt can change spell $ s $ to $ t $ and "NO" otherwise. You can output the answer in any case (for example, lines "yEs", "yes", "Yes" and "YES" will be recognized as positive answer).

输入输出样例

输入样例 #1

7
6 3
talant
atltna
7 3
abacaba
aaaabbc
12 3
abracadabraa
avadakedavra
5 3
accio
cicao
5 3
lumos
molus
4 3
uwjt
twju
4 3
kvpx
vxpk

输出样例 #1

YES
YES
NO
YES
NO
YES
NO

说明

The first example is explained in the condition. In the second example we can proceed as follows: - Swap the letters at positions $ 2 $ and $ 5 $ (distance $ 3 $ ), then we get the spell "aaacbba". - Swap the letters at positions $ 4 $ and $ 7 $ (distance $ 3 $ ), then you get the spell "aaaabbc". In the third example, we can show that it is impossible to get the string $ t $ from the string $ s $ by swapping the letters at a distance of $ 3 $ or $ 4 $ . In the fourth example, for example, the following sequence of transformations is appropriate: - "accio" $ \rightarrow $ "aocic" $ \rightarrow $ "cocia" $ \rightarrow $ "iocca" $ \rightarrow $ "aocci" $ \rightarrow $ "aicco" $ \rightarrow $ "cicao" In the fifth example, you can show that it is impossible to get the string $ s $ from the string $ t $ . In the sixth example, it is enough to swap the two outermost letters.

Input

题意翻译

与 E2 的差异仅在 $k$ 的取值不同。 给定两个长度为 $n$ 的字符串 $s_1,s_2$ 以及一个正整数 $k$,你可以进行任意次操作(可以不操作): 若 $|i-j|=k$ 或 $|i-j|=k+1$,交换 $s_2$ 第 $i$ 个位置的字符与第 $j$ 个位置的字符。 问最终能否使得 $s_1,s_2$ 完全相同。 本题有多组测试数据。 $1\leq T\leq 10^4,1\leq n\leq 2\times 10^5,k=3,\sum n\leq 2\times 10^5$ translated by @[StayAlone](https://www.luogu.com.cn/user/409236)

Output

题目大意:
这个题目是“不可饶恕的诅咒”的简单版本。在这个版本中,$ k $ 的值始终为 3。

题目描述了这样一个情景:魔法部长抓住了邪恶巫师德拉科特,但德拉科特回归了,并想要向部长复仇。所以他从一个学生哈利那里偷走了一个咒语 $ s $。

这个咒语 $ s $ 是一个由小写拉丁字母组成的长度为 $ n $ 的字符串。

德拉科特想要用一句不可饶恕的诅咒——字符串 $ t $ 来替换这个咒语。

德拉科特可以使用古老的魔法,在咒语中距离为 $ k $ 或 $ k+1 $ 的位置交换字母,次数不限。在这个问题的版本中,他可以在距离为 3 或 4 的位置交换字母。换句话说,如果 $ |i-j|=3 $ 或 $ |i-j|=4 $,德拉科特可以在咒语 $ s $ 的位置 $ i $ 和 $ j $ 交换字母。

例如,如果 $ s = $ "talant" 和 $ t = $ "atltna",德拉科特可以这样操作:

- 交换位置 1 和 4 的字母,得到咒语 "aaltnt"。
- 交换位置 2 和 6 的字母,得到咒语 "atltna"。

给你咒语 $ s $ 和 $ t $,问德拉科特能否将咒语 $ s $ 变为 $ t $。

输入输出格式:
输入格式:
第一行输入一个整数 $ T $ ($ 1 \le T \le 10^4 $) —— 测试用例的数量。

接下来是 $ T $ 个测试用例的描述。

每个测试用例的第一行包含两个整数 $ n, k $ ($ 1 \le n \le 2 \times 10^5 $, $ k = 3 $) —— 咒语的长度和数字 $ k $,使得德拉科特可以在距离 $ k $ 或 $ k+1 $ 的位置交换字母。

第二行给出咒语 $ s $ —— 一个由 $ n $ 个小写拉丁字母组成的字符串。

第三行给出咒语 $ t $ —— 一个由 $ n $ 个小写拉丁字母组成的字符串。

保证所有测试用例的 $ n $ 值之和不超过 $ 2 \times 10^5 $。注意,所有测试用例的 $ k $ 值之和没有限制。

输出格式:
对于每个测试用例,如果德拉科特可以将咒语 $ s $ 变为 $ t $,则输出一行 "YES",否则输出 "NO"。

输入输出样例:
输入样例 #1:
```
7
6 3
talant
atltna
7 3
abacaba
aaaabbc
12 3
abracadabraa
avadakedavra
5 3
accio
cicao
5 3
lumos
molus
4 3
uwjt
twju
4 3
kvpx
vxpk
```
输出样例 #1:
```
YES
YES
NO
YES
NO
YES
NO
```

说明:
第一个示例在题目条件中已经解释。

在第二个示例中,我们可以按以下步骤进行:

- 交换位置 2 和 5 的字母(距离 3),然后我们得到咒语 "aaacbba"。
- 交换位置 4 和 7 的字母(距离 3),然后你得到咒语 "aaaabbc"。

在第三个示例中,我们可以证明通过在距离 3 或 4 的位置交换字母,无法从字符串 $ s $ 得到字符串 $ t $。

在第四个示例中,例如,以下变换序列是适当的:

- "accio" -> "aocic" -> "cocia" -> "iocca" -> "aocci" -> "aicco" -> "cicao"

在第五个示例中,你可以证明无法从字符串 $ t $ 得到字符串 $ s $。

在第六个示例中,交换最外层的两个字母就足够了。题目大意: 这个题目是“不可饶恕的诅咒”的简单版本。在这个版本中,$ k $ 的值始终为 3。 题目描述了这样一个情景:魔法部长抓住了邪恶巫师德拉科特,但德拉科特回归了,并想要向部长复仇。所以他从一个学生哈利那里偷走了一个咒语 $ s $。 这个咒语 $ s $ 是一个由小写拉丁字母组成的长度为 $ n $ 的字符串。 德拉科特想要用一句不可饶恕的诅咒——字符串 $ t $ 来替换这个咒语。 德拉科特可以使用古老的魔法,在咒语中距离为 $ k $ 或 $ k+1 $ 的位置交换字母,次数不限。在这个问题的版本中,他可以在距离为 3 或 4 的位置交换字母。换句话说,如果 $ |i-j|=3 $ 或 $ |i-j|=4 $,德拉科特可以在咒语 $ s $ 的位置 $ i $ 和 $ j $ 交换字母。 例如,如果 $ s = $ "talant" 和 $ t = $ "atltna",德拉科特可以这样操作: - 交换位置 1 和 4 的字母,得到咒语 "aaltnt"。 - 交换位置 2 和 6 的字母,得到咒语 "atltna"。 给你咒语 $ s $ 和 $ t $,问德拉科特能否将咒语 $ s $ 变为 $ t $。 输入输出格式: 输入格式: 第一行输入一个整数 $ T $ ($ 1 \le T \le 10^4 $) —— 测试用例的数量。 接下来是 $ T $ 个测试用例的描述。 每个测试用例的第一行包含两个整数 $ n, k $ ($ 1 \le n \le 2 \times 10^5 $, $ k = 3 $) —— 咒语的长度和数字 $ k $,使得德拉科特可以在距离 $ k $ 或 $ k+1 $ 的位置交换字母。 第二行给出咒语 $ s $ —— 一个由 $ n $ 个小写拉丁字母组成的字符串。 第三行给出咒语 $ t $ —— 一个由 $ n $ 个小写拉丁字母组成的字符串。 保证所有测试用例的 $ n $ 值之和不超过 $ 2 \times 10^5 $。注意,所有测试用例的 $ k $ 值之和没有限制。 输出格式: 对于每个测试用例,如果德拉科特可以将咒语 $ s $ 变为 $ t $,则输出一行 "YES",否则输出 "NO"。 输入输出样例: 输入样例 #1: ``` 7 6 3 talant atltna 7 3 abacaba aaaabbc 12 3 abracadabraa avadakedavra 5 3 accio cicao 5 3 lumos molus 4 3 uwjt twju 4 3 kvpx vxpk ``` 输出样例 #1: ``` YES YES NO YES NO YES NO ``` 说明: 第一个示例在题目条件中已经解释。 在第二个示例中,我们可以按以下步骤进行: - 交换位置 2 和 5 的字母(距离 3),然后我们得到咒语 "aaacbba"。 - 交换位置 4 和 7 的字母(距离 3),然后你得到咒语 "aaaabbc"。 在第三个示例中,我们可以证明通过在距离 3 或 4 的位置交换字母,无法从字符串 $ s $ 得到字符串 $ t $。 在第四个示例中,例如,以下变换序列是适当的: - "accio" -> "aocic" -> "cocia" -> "iocca" -> "aocci" -> "aicco" -> "cicao" 在第五个示例中,你可以证明无法从字符串 $ t $ 得到字符串 $ s $。 在第六个示例中,交换最外层的两个字母就足够了。

加入题单

算法标签: