CF903E.Swapping Characters
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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).
我们有一个由 n 个小写拉丁字母组成的字符串 s。我们制作了该字符串的 k 个副本,从而得到 k 个完全相同的字符串 s1,s2,…,sk。随后,在每个字符串中,我们恰好交换了两个字符(被交换的字符可以相同,但它们在字符串中的下标必须不同)。
你将收到 k 个字符串 s1,s2,…,sk,你需要还原出任意一个字符串 s,使得通过上述操作可以得到这些字符串。注意:你所收到的所有字符串的总长度不超过 5000(即 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.
第一行包含两个整数 k 和 n(1 ≤ k ≤ 2500,2 ≤ n ≤ 5000,且 k⋅n ≤ 5000)—— 分别表示我们获得的字符串数量,以及每个字符串的长度。
接下来的 k 行包含字符串 s1,s2,...,sk,每个字符串均由恰好 n 个小写拉丁字母组成。
输出格式
Print any suitable string s, or -1 if such string doesn't exist.
输出任意一个符合条件的字符串 s,如果不存在这样的字符串,则输出 −1。
输入输出样例
输入#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.
在第一个例子中,s1 是通过对字符串 acab 的第二个和第四个字符进行交换得到的,s2 是通过对第一个和第二个字符进行交换得到的,而 s3 则是通过对第三个和第四个字符进行交换得到的。
在第二个例子中,s1 是通过对字符串 kbub 的第三个和第四个字符进行交换得到的,s2 是通过对第二个和第四个字符进行交换得到的,s3 是通过对第一个和第三个字符进行交换得到的。
在第三个例子中,无法通过上述操作得到所给的字符串。
输入解题思路,AI测评打分。不知道怎么写?