codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1360F.md (1791B)


      1 Source: https://codeforces.com/problemset/problem/1360/F
      2 
      3 F. Spy-string
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 You are given $n$ strings $a_1, a_2, \ldots, a_n$: all of them have the same length $m$. The strings consist of lowercase English letters.
     22 
     23 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 $a_i$, there is no more than one position $j$ such that $a_i[j] \ne s[j]$.
     24 
     25 Note that the desired string $s$ may be equal to one of the given strings $a_i$, or it may differ from all the given strings.
     26 
     27 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.
     28 
     29 Input
     30 
     31 The first line contains an integer $t$ ($1 \le t \le 100$) — the number of test cases. Then $t$ test cases follow.
     32 
     33 Each test case starts with a line containing two positive integers $n$ ($1 \le n \le 10$) and $m$ ($1 \le m \le 10$) — the number of strings and their length.
     34 
     35 Then follow $n$ strings $a_i$, one per line. Each of them has length $m$ and consists of lowercase English letters.
     36 
     37 Output
     38 
     39 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).
     40 
     41 Example
     42 
     43 Input
     44 
     45 ```
     46 5
     47 2 4
     48 abac
     49 zbab
     50 2 4
     51 aaaa
     52 bbbb
     53 3 3
     54 baa
     55 aaa
     56 aab
     57 2 2
     58 ab
     59 bb
     60 3 1
     61 a
     62 b
     63 c
     64 ```
     65 
     66 Output
     67 
     68 ```
     69 abab
     70 -1
     71 aaa
     72 ab
     73 z
     74 ```
     75 
     76 Note
     77 
     78 The first test case was explained in the statement.
     79 
     80 In the second test case, the answer does not exist.