A12964 | Swap Letters
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Monocarp has got two strings $s$ and $t$ having equal length. Both strings consist of lowercase Latin letters "a" and "b".
Monocarp wants to make these two strings $s$ and $t$ equal to each other. He can do the following operation any number of times: choose an index $pos_1$ in the string $s$ , choose an index $pos_2$ in the string $t$ , and swap $s_{pos_1}$ with $t_{pos_2}$ .
You have to determine the minimum number of operations Monocarp has to perform to make $s$ and $t$ equal, and print any optimal sequence of operations — or say that it is impossible to make these strings equal.
Monocarp wants to make these two strings $s$ and $t$ equal to each other. He can do the following operation any number of times: choose an index $pos_1$ in the string $s$ , choose an index $pos_2$ in the string $t$ , and swap $s_{pos_1}$ with $t_{pos_2}$ .
You have to determine the minimum number of operations Monocarp has to perform to make $s$ and $t$ equal, and print any optimal sequence of operations — or say that it is impossible to make these strings equal.
输入格式
The first line contains one integer $n$ $(1 \le n \le 2 \cdot 10^{5})$ — the length of $s$ and $t$ .
The second line contains one string $s$ consisting of $n$ characters "a" and "b".
The third line contains one string $t$ consisting of $n$ characters "a" and "b".
The second line contains one string $s$ consisting of $n$ characters "a" and "b".
The third line contains one string $t$ consisting of $n$ characters "a" and "b".
输出格式
If it is impossible to make these strings equal, print $-1$ .
Otherwise, in the first line print $k$ — the minimum number of operations required to make the strings equal. In each of the next $k$ lines print two integers — the index in the string $s$ and the index in the string $t$ that should be used in the corresponding swap operation.
Otherwise, in the first line print $k$ — the minimum number of operations required to make the strings equal. In each of the next $k$ lines print two integers — the index in the string $s$ and the index in the string $t$ that should be used in the corresponding swap operation.
输入输出样例
输入 #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 $s$ with the third letter in $t$ . Then $s = $ "abbb", $t = $ "aaab". Then swap the third letter in $s$ and the second letter in $t$ . Then both $s$ and $t$ are equal to "abab".
In the second example it's impossible to make two strings equal.
In the second example it's impossible to make two strings equal.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted