CF1800E1.Unforgivable Curse (easy version)

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is an easy version of the problem. In this version, kk is always 33.

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 ss from his student Harry.

The spell — is a nn-length string of lowercase Latin letters.

Drahyrt wants to replace spell with an unforgivable curse — string tt.

Drahyrt, using ancient magic, can swap letters at a distance kk or k+1k+1 in spell as many times as he wants. In this version of the problem, you can swap letters at a distance of 33 or 44. In other words, Drahyrt can change letters in positions ii and jj in spell ss if ∣i−j∣=3|i-j|=3 or ∣i−j∣=4|i-j|=4.

For example, if $s = $ "talant" and $t = $ "atltna", Drahyrt can act as follows:

  • swap the letters at positions 11 and 44 to get spell "aaltnt".
  • swap the letters at positions 22 and 66 to get spell "atltna".

You are given spells ss and tt. Can Drahyrt change spell ss to tt?

这是一个该问题的简单版本。在此版本中,kk 恒为 33。

威森加摩首席巫师曾抓住过邪恶巫师德拉赫特,但这位邪恶巫师已卷土重来,意图向首席巫师复仇。因此,他从首席巫师的学生哈利那里窃取了咒语 ss。

该咒语是一个长度为 nn 的、由小写拉丁字母组成的字符串。

德拉赫特希望将咒语 ss 替换为不可饶恕的诅咒——字符串 tt。

德拉赫特借助远古魔法,可以任意多次地交换咒语中距离为 kk 或 k+1k+1 的两个字母。在本题版本中,允许交换距离为 33 或 44 的字母。换言之,德拉赫特可以在咒语 ss 中交换位置 ii 和 jj 上的字母,当且仅当 ∣i−j∣=3|i-j|=3 或 ∣i−j∣=4|i-j|=4。

例如,若 $s = $ "talant" 且 $t = $ "atltna",德拉赫特可按如下方式操作:

  • 交换位置 11 和 44 上的字母,得到咒语 "aaltnt";
  • 交换位置 22 和 66 上的字母,得到咒语 "atltna"。

现给出咒语 ss 和 tt。德拉赫特能否将咒语 ss 变为 tt?

输入格式

The first line of input gives a single integer TT (1≤T≤1041 \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,kn, k (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, k=3k = 3) — the length spells and the number kk such that Drahyrt can change letters in a spell at a distance kk or k+1k+1.

The second line gives spell ss — a string of length nn consisting of lowercase Latin letters.

The third line gives spell tt — a string of length nn consisting of lowercase Latin letters.

It is guaranteed that the sum of nn values over all test cases does not exceed 2⋅1052 \cdot 10^5. Note that there is no limit on the sum of kk values over all test cases.

输入的第一行包含一个整数 TT(1≤T≤1041 \le T \le 10^4)——表示测试用例的数量。

随后是各测试用例的描述。

第一行包含两个整数 n,kn, k(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, k=3k = 3)——分别表示咒语的长度以及参数 kk,Drahyrt 可以在距离为 kk 或 k+1k+1 的位置上修改咒语中的字母。

第二行给出咒语 ss —— 一个长度为 nn 的字符串,由小写拉丁字母组成。

第三行给出咒语 tt —— 一个长度为 nn 的字符串,由小写拉丁字母组成。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。注意:对所有测试用例而言,kk 的总和没有限制。

输出格式

For each test case, output on a separate line "YES" if Drahyrt can change spell ss to tt 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).

对于每个测试用例,如果德拉希尔特可以将法术 ss 变为 tt,则在单独一行输出 “YES”,否则输出 “NO”。

您可以以任意大小写形式输出答案(例如,“yEs”、“yes”、“Yes” 和 “YES” 均会被识别为肯定回答)。

输入输出样例

  • 输入#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 22 and 55 (distance 33), then we get the spell "aaacbba".
  • Swap the letters at positions 44 and 77 (distance 33), then you get the spell "aaaabbc".

In the third example, we can show that it is impossible to get the string tt from the string ss by swapping the letters at a distance of 33 or 44.

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 ss from the string tt.

In the sixth example, it is enough to swap the two outermost letters.

第一个示例已在题目条件中说明。

在第二个示例中,我们可以按如下方式操作:

  • 交换位置 22 和 55(距离为 33)处的字母,得到咒语 "aaacbba";
  • 交换位置 44 和 77(距离为 33)处的字母,得到咒语 "aaaabbc"。

在第三个示例中,可以证明:无法通过交换距离为 33 或 44 的字母,将字符串 ss 变为字符串 tt。

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

  • "accio" →\rightarrow "aocic" →\rightarrow "cocia" →\rightarrow "iocca" →\rightarrow "aocci" →\rightarrow "aicco" →\rightarrow "cicao"

在第五个示例中,可以证明:无法通过交换将字符串 ss 变为字符串 tt。

在第六个示例中,仅需交换最外侧的两个字母即可。

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

首页