A15844 | Unforgivable Curse (easy version)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 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.
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).
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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted