CF1654F.Minimal String Xoration
普及/提高-
通过率:0%
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 .
输入格式
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.
输出格式
Print a single line containing the lexicographically minimal xoration of 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.