CF1546B.AquaMoon and Stolen String

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

AquaMoon had nn strings of length mm each. nn is an odd number.

When AquaMoon was gone, Cirno tried to pair these nn strings together. After making n−12\frac{n-1}{2} pairs, she found out that there was exactly one string without the pair!

In her rage, she disrupted each pair of strings. For each pair, she selected some positions (at least 11 and at most mm) and swapped the letters in the two strings of this pair at the selected positions.

For example, if m=6m = 6 and two strings "abcdef" and "xyzklm" are in one pair and Cirno selected positions 22, 33 and 66 she will swap 'b' with 'y', 'c' with 'z' and 'f' with 'm'. The resulting strings will be "ayzdem" and "xbcklf".

Cirno then stole away the string without pair and shuffled all remaining strings in arbitrary order.

AquaMoon found the remaining n−1n-1 strings in complete disarray. Also, she remembers the initial nn strings. She wants to know which string was stolen, but she is not good at programming. Can you help her?

AquaMoon 有 nn 个长度均为 mm 的字符串,其中 nn 是奇数。

当 AquaMoon 离开后,Cirno 尝试将这 nn 个字符串两两配对。在组成 n−12\frac{n-1}{2} 对之后,她发现恰好剩下一个字符串无法配对!

盛怒之下,她打乱了每一对字符串:对每一对字符串,她选定若干个位置(至少 11 个,至多 mm 个),并在这些选定的位置上交换该对中两个字符串的对应字符。

例如,若 m=6m = 6,一对字符串为 "abcdef" 和 "xyzklm",而 Cirno 选定了位置 22、33 和 66,则她会交换 'b' 与 'y'、'c' 与 'z'、'f' 与 'm',得到的新字符串为 "ayzdem" 和 "xbcklf"。

接着,Cirno 偷走了那个未配对的字符串,并将所有其余字符串以任意顺序打乱。

AquaMoon 发现剩下的 n−1n-1 个字符串完全混乱无序。此外,她还记得最初的 nn 个字符串。她想知道哪个字符串被偷走了,但她不擅长编程。你能帮她吗?

输入格式

This problem is made as interactive. It means, that your solution will read the input, given by the interactor. But the interactor will give you the full input at the beginning and after that, you should print the answer. So you should solve the problem, like as you solve the usual, non-interactive problem because you won't have any interaction process. The only thing you should not forget is to flush the output buffer, after printing the answer. Otherwise, you can get an "Idleness limit exceeded" verdict. Refer to the interactive problems guide for the detailed information about flushing the output buffer.

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1001 \leq t \leq 100) — the number of test cases.

The first line of each test case contains two integers nn, mm (1≤n≤1051 \leq n \leq 10^5, 1≤m≤1051 \leq m \leq 10^5) — the number of strings and the length of each string, respectively.

The next nn lines each contain a string with length mm, describing the original nn strings. All string consists of lowercase Latin letters.

The next n−1n-1 lines each contain a string with length mm, describing the strings after Cirno exchanged and reordered them.

It is guaranteed that nn is odd and that the sum of n⋅mn \cdot m over all test cases does not exceed 10510^5.

Hack format:

The first line should contain a single integer tt. After that tt test cases should follow in the following format:

The first line should contain two integers nn and mm.

The following nn lines should contain nn strings of length mm, describing the original strings.

The following n−12\frac{n-1}{2} lines should describe the pairs. They should contain, in the following order: the index of the first string ii (1≤i≤n1 \leq i \leq n), the index of the second string jj (1≤j≤n1 \leq j \leq n, i≠ji \neq j), the number of exchanged positions kk (1≤k≤m1 \leq k \leq m), and the list of kk positions that are exchanged (kk distinct indices from 11 to mm in any order).

The final line should contain a permutation of integers from 11 to nn, describing the way the strings should be reordered. The strings will be placed in the order indices placed in this permutation, the stolen string index will be ignored.

本题为交互式题目。这意味着你的程序将读取由交互器(interactor)提供的输入。但交互器会在开始时一次性给出全部输入,之后你只需输出答案即可。因此,你应像求解普通非交互式题目一样求解本题,因为实际并不存在交互过程。你唯一需要注意的是:在输出答案后,必须刷新输出缓冲区;否则,你可能会收到 “Idleness limit exceeded”(空闲时间超限)的判题结果。关于刷新输出缓冲区的详细信息,请参阅交互式题目指南。

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100),表示测试用例的数量。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n≤1051 \leq n \leq 10^5,1≤m≤1051 \leq m \leq 10^5),分别表示字符串的数量以及每个字符串的长度。

接下来的 nn 行,每行包含一个长度为 mm 的字符串,描述原始的 nn 个字符串。所有字符串均由小写拉丁字母组成。

再接下来的 n−1n-1 行,每行包含一个长度为 mm 的字符串,描述 Cirno 交换并重新排序后的字符串。

保证 nn 为奇数,且所有测试用例中 n⋅mn \cdot m 的总和不超过 10510^5。

Hack 格式:

第一行应为一个整数 tt。随后是 tt 个测试用例,格式如下:

第一行应包含两个整数 nn 和 mm。

接下来的 nn 行,每行包含一个长度为 mm 的字符串,描述原始的 nn 个字符串。

再接下来的 n−12\frac{n-1}{2} 行用于描述交换操作对。每行应按以下顺序包含:第一个字符串的索引 ii(1≤i≤n1 \leq i \leq n)、第二个字符串的索引 jj(1≤j≤n1 \leq j \leq n,且 i≠ji \neq j)、交换的位置数量 kk(1≤k≤m1 \leq k \leq m),以及 kk 个待交换的位置(即 kk 个互不相同的、取值范围为 11 到 mm 的下标,顺序任意)。

最后一行应为 11 到 nn 的一个排列,表示字符串应被重排成的顺序。字符串将按照该排列中所列索引的顺序放置,而被窃取的字符串的索引将被忽略。

输出格式

For each test case print a single line with the stolen string.

对于每个测试用例,输出一行被盗的字符串。

输入输出样例

  • 输入#1

    3
    3 5
    aaaaa
    bbbbb
    ccccc
    aaaaa
    bbbbb
    3 4
    aaaa
    bbbb
    cccc
    aabb
    bbaa
    5 6
    abcdef
    uuuuuu
    kekeke
    ekekek
    xyzklm
    xbcklf
    eueueu
    ayzdem
    ukukuk

    输出#1

    ccccc
    cccc
    kekeke

说明/提示

In the first test case, "aaaaa" and "bbbbb" exchanged all positions, and "ccccc" is the stolen string.

In the second test case, "aaaa" and "bbbb" exchanged two first positions, and "cccc" is the stolen string.

This is the first test in the hack format:

3
3 5
aaaaa
bbbbb
ccccc
1 2 5 1 2 3 4 5
2 1 3
3 4
aaaa
bbbb
cccc
1 2 2 1 2
2 1 3
5 6
abcdef
uuuuuu
kekeke
ekekek
xyzklm
1 5 3 2 3 6
2 4 3 2 4 6
5 4 1 2 3

在第一个测试用例中,“aaaaa”与“bbbbb”交换了所有位置,而“ccccc”是被窃取的字符串。

在第二个测试用例中,“aaaa”与“bbbb”交换了前两个位置,而“cccc”是被窃取的字符串。

这是 Hack 格式下的第一个测试:

3
3 5
aaaaa
bbbbb
ccccc
1 5 3 2 3 6
2 4 3 2 4 6
5 4 1 2 3
2 1 3
3 4
aaaa
bbbb
cccc
1 2 2 1 2
2 1 3
5 6
abcdef
uuuuuu
kekeke
ekekek
xyzklm
1 5 3 2 3 6
2 4 3 2 4 6
5 4 1 2 3

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

首页