QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 10

#1383. 玩具 [C]

Statistics

也许你不知道,兄弟 Bituś 和 Bajtuś 拥有相当令人印象深刻的玩具收藏!每位兄弟都有 $n$ 个玩具,每个玩具属于 26 种类型中的一种。为了方便起见,兄弟俩用英文字母表中的连续字母(从 a 到 z)标记了每种类型的玩具。

在今天的游戏中,Bituś 取出了他的玩具,并将它们从左到右排成一列。因此,Bituś 可以用一个包含 $n$ 个英文字符的字符串来描述他玩具的排列;该字符串的第 $i$ 个字符表示从左往右数的第 $i$ 个玩具。Bajtuś 也取出了他的玩具,并将它们从左到右排成一列。现在,Bituś 想要变得和 Bajtuś 一样——使他的玩具排列顺序与 Bajtuś 的玩具排列顺序完全相同。

在游戏过程中,Bituś 可以通过以下操作改变玩具的顺序:每次操作可以选择一段长度为奇数的连续玩具,并将它们的顺序反转。例如,如果字符串 abcdea 描述了 Bituś 玩具的顺序,那么在一次操作中,Bituś 可以得到例如 adcbea(通过反转从第二个到第四个玩具的顺序)或 edcbaa(通过反转从第一个到第五个玩具的顺序)。然而,他不能在一次操作中得到 bacdea

Bituś 是否能够使他的玩具排列顺序与 Bajtuś 的玩具排列顺序完全相同?

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 300\,000$),表示 Bituś 拥有的玩具数量(同时也是 Bajtuś 拥有的玩具数量)。第二行包含一个长度为 $n$ 的英文字符串(从 a 到 z),描述了游戏开始时 Bituś 的玩具排列。第三行描述了 Bajtuś 的玩具排列,格式与第二行相同。

输出格式

如果 Bituś 可以通过反转操作将他的初始玩具排列变为 Bajtuś 的玩具排列,请在唯一的一行输出 TAK。否则,输出 NIE

样例

输入 1

7
abcdefg
edgbcfa

输出 1

TAK

说明 1

在第一个样例中,Bituś 可以通过三次操作从初始排列得到目标排列:

a b c d e f g
e d c b a f g
e d c b g f a
e d g b c f a

输入 2

5
abcde
fghhh

输出 2

NIE

说明 2

第二个样例的答案是 NIE,因为 Bitek 没有目标排列中所需的任何 h 类型玩具。

子任务

部分测试组满足以下性质:如果该组测试的答案为 TAK,则目标玩具排列可以通过最多一次操作从初始排列得到。

此外,约一半的测试组满足 $n \le 2000$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.