QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100

#10658. Transformacje

Statistics

给定两个由字母 ab 组成的单词 $u$ 和 $v$。我们的目标是将单词 $u$ 转换成单词 $v$。为此我们可以进行如下的交换操作:选择 $u$ 中两个 $不相交$ 的片段 abba,并交换它们的位置。是否可以通过有限次这样的操作,将 $u$ 转换为 $v$?

输入格式

输入的第一行包含一个整数 $n$($2 \le n \le 1,000,000$),表示单词的长度。接下来的两行每行包含一个由 $n$ 个 a 和/或 b 组成的字符串。第一行描述单词 $u$,第二行描述单词 $v$。你可以假设这两个单词是不同的。

输出格式

输出的第一行应为一个单词 TAKNIE,表示是否可以仅通过交换操作将单词 $u$ 转换为单词 $v$。

如果答案是肯定的, $n \le 4,000$,你的程序还应输出一个实现目标的操作序列示例。这个描述的第一行应为一个整数 $m$($1 \le m \le 1,000,000$),表示操作的次数。接下来的 $m$ 行每行包含两个整数 $a_{i}$、$b_{i}$($1 \le a_{i}, b_{i} \le n - 1$),分别表示被交换的 ab 片段和 ba 片段的首字母的位置。

如果存在多个可能的方案,你的程序可以输出其中任意一个。特别地,你的方案不必使操作次数 $m$ 最小化。

样例

输入

6
aabbaa
baaaab

输出

TAK
2
2 4
1 5

输入 2

6
aaabbb
ababab

输出 2

NIE
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.