Codeforces Round 778 (Div. 1 + Div. 2, based on Technocup 2022 Final Round)
F
Minimal String Xoration
Codeforces
2800
原题
← EG →
翻译中…

You are given an integer $n$ and a string $s$ consisting of $2^n$ lowercase letters of the English alphabet. The characters of the string $s$ are $s_0s_1s_2\cdots s_{2^n-1}$.

翻译中…

A string $t$ of length $2^n$ (whose characters are denoted by $t_0t_1t_2\cdots t_{2^n-1}$) is a xoration of $s$ if there exists an integer $j$ ($0\le j \leq 2^n-1$) such that, for each $0 \leq i \leq 2^n-1$, $t_i = s_{i \oplus j}$ (where $\oplus$ 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 \ne 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$.
翻译中…

Input

翻译中…

The first line contains a single integer $n$ ($1 \le n \le 18$).

翻译中…

The second line contains a string $s$ consisting of $2^n$ lowercase letters of the English alphabet.

翻译中…

Output

翻译中…

Print a single line containing the lexicographically minimal xoration of $s$.

翻译中…

Note

翻译中…

In the first test, the lexicographically minimal xoration $t$ of $s =$"acba" is "abca". It's a xoration because, for $j = 3$,

翻译中…
  • $t_0 = s_{0 \oplus j} = s_3 =$ "a";
  • $t_1 = s_{1 \oplus j} = s_2 =$ "b";
  • $t_2 = s_{2 \oplus j} = s_1 =$ "c";
  • $t_3 = s_{3 \oplus j} = s_0 =$ "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.

翻译中…

样例

Input #1
2
acba
Output #1
abca
InputCopy OutputCopy
Input #2
3
bcbaaabb
Output #2
aabbbcba
InputCopy OutputCopy
Input #3
4
bdbcbccdbdbaaccd
Output #3
abdbdccacbdbdccb
InputCopy OutputCopy
Input #4
5
ccfcffccccccffcfcfccfffffcccccff
Output #4
cccccffffcccccffccfcffcccccfffff
InputCopy OutputCopy
Input #5
1
zz
Output #5
zz
InputCopy OutputCopy
题目信息
题号
1654F
时间限制
3 s
内存限制
512 MB
标签
位运算
数据结构
分治
贪心
哈希
排序
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。