A14900 | Minimal String Xoration
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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](https://en.wikipedia.org/wiki/Bitwise_operation#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$ .
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](https://en.wikipedia.org/wiki/Bitwise_operation#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$ .
输入格式
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.
The second line contains a string $s$ consisting of $2^n$ 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$ ,
- $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.
- $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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted