A11561 | Swapping Characters
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
We had a string $s$ consisting of $n$ lowercase Latin letters. We made $k$ copies of this string, thus obtaining $k$ identical strings $s_{1},s_{2},...,s_{k}$ . After that, in each of these strings we swapped exactly two characters (the characters we swapped could be identical, but they had different indices in the string).
You are given $k$ strings $s_{1},s_{2},...,s_{k}$ , and you have to restore any string $s$ so that it is possible to obtain these strings by performing aforementioned operations. Note that the total length of the strings you are given doesn't exceed 5000 (that is, $k·n<=5000$ ).
You are given $k$ strings $s_{1},s_{2},...,s_{k}$ , and you have to restore any string $s$ so that it is possible to obtain these strings by performing aforementioned operations. Note that the total length of the strings you are given doesn't exceed 5000 (that is, $k·n<=5000$ ).
输入格式
The first line contains two integers $k$ and $n$ ( $1<=k<=2500,2<=n<=5000,k · n<=5000$ ) — the number of strings we obtained, and the length of each of these strings.
Next $k$ lines contain the strings $s_{1},s_{2},...,s_{k}$ , each consisting of exactly $n$ lowercase Latin letters.
Next $k$ lines contain the strings $s_{1},s_{2},...,s_{k}$ , each consisting of exactly $n$ lowercase Latin letters.
输出格式
Print any suitable string $s$ , or -1 if such string doesn't exist.
输入输出样例
输入 #1
3 4 abac caab acba
输出 #1
acab
输入 #2
3 4 kbbu kbub ubkb
输出 #2
kbub
输入 #3
5 4 abcd dcba acbd dbca zzzz
输出 #3
-1
In the first example $s_{1}$ is obtained by swapping the second and the fourth character in acab, $s_{2}$ is obtained by swapping the first and the second character, and to get $s_{3}$ , we swap the third and the fourth character.
In the second example $s_{1}$ is obtained by swapping the third and the fourth character in kbub, $s_{2}$ — by swapping the second and the fourth, and $s_{3}$ — by swapping the first and the third.
In the third example it's impossible to obtain given strings by aforementioned operations.
In the second example $s_{1}$ is obtained by swapping the third and the fourth character in kbub, $s_{2}$ — by swapping the second and the fourth, and $s_{3}$ — by swapping the first and the third.
In the third example it's impossible to obtain given strings by aforementioned operations.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted