CF1215C.Swap Letters

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Monocarp has got two strings ss and tt having equal length. Both strings consist of lowercase Latin letters "a" and "b".

Monocarp wants to make these two strings ss and tt equal to each other. He can do the following operation any number of times: choose an index pos1pos_1 in the string ss, choose an index pos2pos_2 in the string tt, and swap spos1s_{pos_1} with tpos2t_{pos_2}.

You have to determine the minimum number of operations Monocarp has to perform to make ss and tt equal, and print any optimal sequence of operations — or say that it is impossible to make these strings equal.

Monocarp 有两个长度相等的字符串 ss 和 tt,它们均由小写拉丁字母 “a” 和 “b” 组成。

Monocarp 希望使这两个字符串 ss 和 tt 相等。他可以执行以下操作任意多次:在字符串 ss 中选择一个下标 pos1pos_1,在字符串 tt 中选择一个下标 pos2pos_2,然后交换 spos1s_{pos_1} 与 tpos2t_{pos_2}。

你需要确定 Monocarp 为使 ss 和 tt 相等所需执行的最少操作次数,并输出任意一组最优操作序列;若无法使这两个字符串相等,则说明这是不可能的。

输入格式

The first line contains one integer nn (1≤n≤2⋅105)(1 \le n \le 2 \cdot 10^{5}) — the length of ss and tt.

The second line contains one string ss consisting of nn characters "a" and "b".

The third line contains one string tt consisting of nn characters "a" and "b".

第一行包含一个整数 nn (1≤n≤2⋅105)(1 \le n \le 2 \cdot 10^{5}) —— 字符串 ss 和 tt 的长度。

第二行包含一个由 nn 个字符 "a" 和 "b" 组成的字符串 ss。

第三行包含一个由 nn 个字符 "a" 和 "b" 组成的字符串 tt。

输出格式

If it is impossible to make these strings equal, print −1-1.

Otherwise, in the first line print kk — the minimum number of operations required to make the strings equal. In each of the next kk lines print two integers — the index in the string ss and the index in the string tt that should be used in the corresponding swap operation.

如果无法使这两个字符串相等,则输出 −1-1。

否则,在第一行输出 kk —— 使字符串相等所需的最少操作次数。接下来的 kk 行中,每行输出两个整数 —— 分别为字符串 ss 和字符串 tt 中在对应交换操作中应使用的下标。

输入输出样例

  • 输入#1

    4
    abab
    aabb

    输出#1

    2
    3 3
    3 2
  • 输入#2

    1
    a
    b

    输出#2

    -1
  • 输入#3

    8
    babbaabb
    abababaa

    输出#3

    3
    2 6
    1 3
    7 8

说明/提示

In the first example two operations are enough. For example, you can swap the third letter in ss with the third letter in tt. Then $s = $ "abbb", $t = $ "aaab". Then swap the third letter in ss and the second letter in tt. Then both ss and tt are equal to "abab".

In the second example it's impossible to make two strings equal.

在第一个例子中,两次操作就足够了。例如,您可以交换 ss 的第三个字母与 tt 的第三个字母,此时 $s = $ “abbb”,$t = $ “aaab”。然后交换 ss 的第三个字母与 tt 的第二个字母,此时 ss 和 tt 均变为 “abab”。

在第二个例子中,无法使两个字符串相等。

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

首页