CF1654F.Minimal String Xoration
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer n and a string s consisting of 2n lowercase letters of the English alphabet. The characters of the string s are s0s1s2⋯s2n−1.
A string t of length 2n (whose characters are denoted by t0t1t2⋯t2n−1) is a xoration of s if there exists an integer j (0≤j≤2n−1) such that, for each 0≤i≤2n−1, ti=si⊕j (where ⊕ denotes the operation bitwise XOR).
Find the lexicographically minimal xoration of s.
A string a is lexicographically smaller than a string b if and only if one of the following holds:
- a is a prefix of b, but a=b;
- in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b.
给定一个整数 n 和一个由 2n 个小写英文字母组成的字符串 s。字符串 s 的字符表示为 s0s1s2⋯s2n−1。
长度为 2n 的字符串 t(其字符表示为 t0t1t2⋯t2n−1)被称为 s 的一个异或变换(xoration),当且仅当存在一个整数 j(满足 0≤j≤2n−1),使得对每个 0≤i≤2n−1,均有 ti=si⊕j(其中 ⊕ 表示按位异或运算)。
请找出 s 的字典序最小的异或变换。
字符串 a 字典序小于字符串 b,当且仅当满足以下条件之一:
- a 是 b 的真前缀(即 a 是 b 的前缀且 a=b);
- 在 a 与 b 首次出现不同字符的位置上,a 中该位置的字母在字母表中早于 b 中对应位置的字母。
输入格式
The first line contains a single integer n (1≤n≤18).
The second line contains a string s consisting of 2n lowercase letters of the English alphabet.
第一行包含一个整数 n(1≤n≤18)。
第二行包含一个字符串 s,由 2n 个小写英文字母组成。
输出格式
Print a single line containing the lexicographically minimal xoration of s.
输出一行,包含字符串 s 的字典序最小的异或变换结果。
输入输出样例
输入#1
2 acba
输出#1
abca
输入#2
3 bcbaaabb
输出#2
aabbbcba
输入#3
4 bdbcbccdbdbaaccd
输出#3
abdbdccacbdbdccb
输入#4
5 ccfcffccccccffcfcfccfffffcccccff
输出#4
cccccffffcccccffccfcffcccccfffff
输入#5
1 zz
输出#5
zz
说明/提示
In the first test, the lexicographically minimal xoration t of s="acba" is "abca". It's a xoration because, for j=3,
- t0=s0⊕j=s3= "a";
- t1=s1⊕j=s2= "b";
- t2=s2⊕j=s1= "c";
- t3=s3⊕j=s0= "a".
There isn't any xoration of s lexicographically smaller than "abca".
In the second test, the minimal string xoration corresponds to choosing j=4 in the definition of xoration.
In the third test, the minimal string xoration corresponds to choosing j=11 in the definition of xoration.
In the fourth test, the minimal string xoration corresponds to choosing j=10 in the definition of xoration.
In the fifth test, the minimal string xoration corresponds to choosing either j=0 or j=1 in the definition of xoration.
在第一个测试中,字符串 s= "acba" 的字典序最小异或变换 t 为 "abca"。它是一个异或变换,因为当 j=3 时,
- t0=s0⊕j=s3= "a";
- t1=s1⊕j=s2= "b";
- t2=s2⊕j=s1= "c";
- t3=s3⊕j=s0= "a"。
不存在字典序比 "abca" 更小的 s 的异或变换。
在第二个测试中,字典序最小的字符串异或变换对应于异或变换定义中选择 j=4。
在第三个测试中,字典序最小的字符串异或变换对应于异或变换定义中选择 j=11。
在第四个测试中,字典序最小的字符串异或变换对应于异或变换定义中选择 j=10。
在第五个测试中,字典序最小的字符串异或变换对应于异或变换定义中选择 j=0 或 j=1。
输入解题思路,AI测评打分。不知道怎么写?