CF1688C.Manipulating History

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

As a human, she can erase history of its entirety. As a Bai Ze (Hakutaku), she can create history out of nothingness.

—Perfect Memento in Strict Sense

Keine has the ability to manipulate history.

The history of Gensokyo is a string ss of length 11 initially. To fix the chaos caused by Yukari, she needs to do the following operations nn times, for the ii-th time:

  • She chooses a non-empty substring t2i−1t_{2i-1} of ss.
  • She replaces t2i−1t_{2i-1} with a non-empty string, t2it_{2i}. Note that the lengths of strings t2i−1t_{2i-1} and t2it_{2i} can be different.

Note that if t2i−1t_{2i-1} occurs more than once in ss, exactly one of them will be replaced.

For example, let s=s="marisa", t2i−1=t_{2i-1}="a", and t2i=t_{2i}="z". After the operation, ss becomes "mzrisa" or "marisz".

After nn operations, Keine got the final string and an operation sequence tt of length 2n2n. Just as Keine thinks she has finished, Yukari appears again and shuffles the order of tt. Worse still, Keine forgets the initial history.

Help Keine find the initial history of Gensokyo!

Recall that a substring is a sequence of consecutive characters of the string. For example, for string "abc" its substrings are: "ab", "c", "bc" and some others. But the following strings are not its substring: "ac", "cba", "acb".

Hacks

You cannot make hacks in this problem.

作为人类,她能彻底抹去历史;作为白泽(Hakutaku),她能凭空创造历史。

——《严格意义下的完美秘录》

凯宁拥有操控历史的能力。

幻想乡的历史最初是一个长度为 11 的字符串 ss。为了修复由八云紫引发的混乱,她需要执行 nn 次如下操作,第 ii 次操作如下:

  • 她从 ss 中选择一个非空子串 t2i−1t_{2i-1};
  • 她将 t2i−1t_{2i-1} 替换为一个非空字符串 t2it_{2i}。注意:t2i−1t_{2i-1} 与 t2it_{2i} 的长度可以不同。

注意:若 t2i−1t_{2i-1} 在 ss 中出现多次,则仅替换其中某一次出现(即恰好一个)。

例如,设 s=s = "marisa",t2i−1=t_{2i-1} = "a",t2i=t_{2i} = "z"。操作后,ss 将变为 "mzrisa" 或 "marisz"。

经过 nn 次操作后,凯宁得到了最终字符串以及一个长度为 2n2n 的操作序列 tt。正当凯宁以为任务完成之时,八云紫再次现身,打乱了 tt 中各元素的顺序。更糟的是,凯宁忘记了初始的历史字符串。

请帮助凯宁找出幻想乡的初始历史!

回顾:子串是指字符串中连续的一段字符构成的序列。例如,对字符串 "abc",其子串包括:"ab"、"c"、"bc" 等;但以下字符串不是它的子串:"ac"、"cba"、"acb"。

Hack

本题不允许 Hack。

输入格式

Each test contains multiple test cases. The first line contains a single integer TT (1≤T≤1031 \leq T \leq 10^3) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n<1051 \le n \lt 10 ^ 5) — the number of operations.

The next 2n2n lines contains one non-empty string tit_{i} — the ii-th string of the shuffled sequence tt.

The next line contains one non-empty string ss — the final string.

It is guaranteed that the total length of given strings (including tit_i and ss) over all test cases does not exceed 2⋅1052 \cdot 10 ^ 5. All given strings consist of lowercase English letters only.

It is guaranteed that the initial string exists. It can be shown that the initial string is unique.

每个测试包含多个测试用例。第一行包含一个整数 TT(1≤T≤1031 \leq T \leq 10^3),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n<1051 \le n \lt 10 ^ 5),表示操作次数。

接下来的 2n2n 行,每行包含一个非空字符串 tit_{i},即打乱顺序后的序列 tt 的第 ii 个字符串。

下一行包含一个非空字符串 ss,即最终字符串。

保证所有测试用例中给定字符串(包括所有 tit_i 和 ss)的总长度不超过 2⋅1052 \cdot 10 ^ 5。所有给定字符串仅由小写英文字母组成。

保证初始字符串存在,且可以证明该初始字符串是唯一的。

输出格式

For each test case, print the initial string in one line.

对于每个测试用例,在一行中输出初始字符串。

输入输出样例

  • 输入#1

    2
    2
    a
    ab
    b
    cd
    acd
    3
    z
    a
    a
    aa
    yakumo
    ran
    yakumoran

    输出#1

    a
    z

说明/提示

Test case 1:

Initially ss is "a".

  • In the first operation, Keine chooses "a", and replaces it with "ab". ss becomes "ab".
  • In the second operation, Keine chooses "b", and replaces it with "cd". ss becomes "acd".

So the final string is "acd", and t=[t=["a", "ab", "b", "cd"]] before being shuffled.

Test case 2:

Initially ss is "z".

  • In the first operation, Keine chooses "z", and replaces it with "aa". ss becomes "aa".
  • In the second operation, Keine chooses "a", and replaces it with "ran". ss becomes "aran".
  • In the third operation, Keine chooses "a", and replaces it with "yakumo". ss becomes "yakumoran".

So the final string is "yakumoran", and t=[t=["z", "aa", "a", "ran", "a", "yakumo"]] before being shuffled.

测试用例 1:

初始时 ss 为 "a"。

  • 在第一次操作中,Keine 选择 "a",并将其替换为 "ab"。ss 变为 "ab"。
  • 在第二次操作中,Keine 选择 "b",并将其替换为 "cd"。ss 变为 "acd"。

因此最终字符串为 "acd",且在打乱前 t=[t=["a", "ab", "b", "cd"]]。

测试用例 2:

初始时 ss 为 "z"。

  • 在第一次操作中,Keine 选择 "z",并将其替换为 "aa"。ss 变为 "aa"。
  • 在第二次操作中,Keine 选择 "a",并将其替换为 "ran"。ss 变为 "aran"。
  • 在第三次操作中,Keine 选择 "a",并将其替换为 "yakumo"。ss 变为 "yakumoran"。

因此最终字符串为 "yakumoran",且在打乱前 t=[t=["z", "aa", "a", "ran", "a", "yakumo"]]。

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

首页