CF1360F.Spy-string
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given n strings a1,a2,…,an: all of them have the same length m. The strings consist of lowercase English letters.
Find any string s of length m such that each of the given n strings differs from s in at most one position. Formally, for each given string ai, there is no more than one position j such that ai[j]=s[j].
Note that the desired string s may be equal to one of the given strings ai, or it may differ from all the given strings.
For example, if you have the strings abac and zbab, then the answer to the problem might be the string abab, which differs from the first only by the last character, and from the second only by the first.
给你 n 个字符串 a1,a2,…,an,它们的长度均为 m。这些字符串仅由小写英文字母组成。
请找出任意一个长度为 m 的字符串 s,使得给定的 n 个字符串中每一个都至多在一个位置上与 s 不同。形式化地说,对每个给定的字符串 ai,满足 ai[j]=s[j] 的位置 j 的个数不超过 1。
注意:所求字符串 s 可以恰好等于某个给定的字符串 ai,也可以与所有给定字符串均不相同。
例如,若给定字符串为 abac 和 zbab,则本题的一个可能答案是字符串 abab:它仅在最后一个字符处与第一个字符串不同,且仅在第一个字符处与第二个字符串不同。
输入格式
The first line contains an integer t (1≤t≤100) — the number of test cases. Then t test cases follow.
Each test case starts with a line containing two positive integers n (1≤n≤10) and m (1≤m≤10) — the number of strings and their length.
Then follow n strings ai, one per line. Each of them has length m and consists of lowercase English letters.
第一行包含一个整数 t(1≤t≤100)—— 表示测试用例的数量。随后是 t 个测试用例。
每个测试用例以一行开始,该行包含两个正整数 n(1≤n≤10)和 m(1≤m≤10)—— 分别表示字符串的个数及其长度。
接下来是 n 个字符串 ai,每行一个。每个字符串长度为 m,且仅由小写英文字母组成。
输出格式
Print t answers to the test cases. Each answer (if it exists) is a string of length m consisting of lowercase English letters. If there are several answers, print any of them. If the answer does not exist, print "-1" ("minus one", without quotes).
输出 t 个测试用例的答案。每个答案(如果存在)是一个长度为 m 的字符串,仅由小写英文字母组成。如果存在多个答案,输出其中任意一个即可。如果答案不存在,则输出 \-1(“减一”,不含引号)。
输入输出样例
输入#1
5 2 4 abac zbab 2 4 aaaa bbbb 3 3 baa aaa aab 2 2 ab bb 3 1 a b c
输出#1
abab -1 aaa ab z
说明/提示
The first test case was explained in the statement.
In the second test case, the answer does not exist.
第一个测试用例已在题目描述中解释。
在第二个测试用例中,答案不存在。
输入解题思路,AI测评打分。不知道怎么写?