CF2194C.Secret message

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Bob, the genius spy, has intercepted an encrypted message. He assumes that it contains secret information and is actively engaged in deciphering it.

The note, which has fallen into the hands of the spy, consists of kk strips, each of length nn and containing strict lowercase Latin letters. With extensive experience in deciphering such documents, Bob guessed that the message he is interested in (the deciphering of the note) is also a string of length nn, and the ii-th letter of this message corresponds to the ii-th letter of one of the strips.

According to Bob, the informativity of a string ss is defined as the minimum positive integer dd such that a string tt of length dd exists, and ss can be formed by repeating tt several times. For example, the informativity of the string "aaaa" is 1, the informativity of the string "abab" is 2, and the informativity of the string "abcd" is 4.

Bob assumes that the note's author, to ensure reliable transmission of information, repeated the data in the message several times. Therefore, he believes that a more plausible decryption of the note would have the smallest possible informativity.

Help the spy: find the message that represents the decryption of the note and has the minimum possible informativity.

天才间谍鲍勃截获了一条加密信息。他推测其中包含秘密情报,正全力进行破译。

落入间谍手中的这张纸条由 kk 条长度均为 nn 的纸带组成,每条纸带上仅包含严格的小写拉丁字母。凭借丰富的此类文件破译经验,鲍勃推测他所关注的(即该纸条的明文)同样是一个长度为 nn 的字符串,且该字符串的第 ii 个字符恰好来自某一条纸带的第 ii 个字符。

根据鲍勃的定义,字符串 ss 的信息量(informativity)是指满足如下条件的最小正整数 dd:存在一个长度为 dd 的字符串 tt,使得 ss 可由 tt 重复若干次构成。例如,字符串 "aaaa" 的信息量为 11,字符串 "abab" 的信息量为 22,字符串 "abcd" 的信息量为 44。

鲍勃认为,为了确保信息可靠传输,原文作者将消息内容重复了若干次。因此,他相信:信息量越小的解密结果,其作为真实明文的可能性越高。

请协助这位间谍:找出一个代表该纸条解密结果、且具有最小可能信息量的字符串。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

In the first line of each test case, there are numbers nn and kk (2≤n,k≤50 000,4≤n⋅k≤1052 \leq n, k \leq 50\,000, 4 \leq n \cdot k \leq 10^5) — the length of the strips of paper and the number of strips.

In each of the following kk lines of each test case, there is a sequence of nn lowercase Latin letters — the next strip.

It is guaranteed that the sum n⋅kn \cdot k across all test cases does not exceed 10510^5

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

在每个测试用例的第一行中,有两个数 nn 和 kk(2≤n,k≤50 0002 \leq n, k \leq 50\,000,且 4≤n⋅k≤1054 \leq n \cdot k \leq 10^5)——分别表示纸条的长度和纸条的数量。

在每个测试用例接下来的 kk 行中,每行包含一个由 nn 个小写拉丁字母组成的序列——即下一条纸条。

保证所有测试用例中 n⋅kn \cdot k 的总和不超过 10510^5。

输出格式

For each test case, output a string of length nn — the decryption of the note, which has the minimal possible informativity. If there are multiple suitable answers, any of them may be output.

对于每个测试用例,输出一个长度为 nn 的字符串——即该便条的解密结果,且其信息量需达到最小可能值。若存在多个符合条件的答案,输出任意一个即可。

输入输出样例

  • 输入#1

    3
    3 2
    abc
    baa
    9 2
    iiinnnfff
    nnfiffinn
    4 2
    acbd
    bdac

    输出#1

    aaa
    infinfinf
    acac

说明/提示

In the first test case, the minimum possible informativity is 11:

abc

baa

In the second test case, the minimum possible informativity is 33:

iiinnnfff

nnfiffinn

在第一个测试用例中,最小可能的信息量为 11:

abc

baa

在第二个测试用例中,最小可能的信息量为 33:

iiinnnfff

nnfiffinn

输入解题思路,AI测评打分。不知道怎么写?

首页