A12608 | Xor Permutations
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Toad Mikhail has an array of $2^k$ integers $a_1, a_2, \ldots, a_{2^k}$ .
Find two permutations $p$ and $q$ of integers $0, 1, \ldots, 2^k-1$ , such that $a_i$ is equal to $p_i \oplus q_i$ for all possible $i$ , or determine there are no such permutations. Here $\oplus$ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Find two permutations $p$ and $q$ of integers $0, 1, \ldots, 2^k-1$ , such that $a_i$ is equal to $p_i \oplus q_i$ for all possible $i$ , or determine there are no such permutations. Here $\oplus$ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
输入格式
The first line contains one integer $k$ ( $2 \leq k \leq 12$ ), denoting that the size of the array is $2^k$ .
The next line contains $2^k$ space-separated integers $a_1, a_2, \ldots, a_{2^k}$ ( $0 \leq a_i < 2^k$ ) — the elements of the given array.
The next line contains $2^k$ space-separated integers $a_1, a_2, \ldots, a_{2^k}$ ( $0 \leq a_i < 2^k$ ) — the elements of the given array.
输出格式
If the given array can't be represented as element-wise XOR of two permutations of integers $0, 1, \ldots, 2^k-1$ , print "Fou".
Otherwise, print "Shi" in the first line.
The next two lines should contain the description of two suitable permutations. The first of these lines should contain $2^k$ space-separated distinct integers $p_{1}, p_{2}, \ldots, p_{2^k}$ , and the second line should contain $2^k$ space-separated distinct integers $q_{1}, q_{2}, \ldots, q_{2^k}$ .
All elements of $p$ and $q$ should be between $0$ and $2^k - 1$ , inclusive; $p_i \oplus q_i$ should be equal to $a_i$ for all $i$ such that $1 \leq i \leq 2^k$ . If there are several possible solutions, you can print any.
Otherwise, print "Shi" in the first line.
The next two lines should contain the description of two suitable permutations. The first of these lines should contain $2^k$ space-separated distinct integers $p_{1}, p_{2}, \ldots, p_{2^k}$ , and the second line should contain $2^k$ space-separated distinct integers $q_{1}, q_{2}, \ldots, q_{2^k}$ .
All elements of $p$ and $q$ should be between $0$ and $2^k - 1$ , inclusive; $p_i \oplus q_i$ should be equal to $a_i$ for all $i$ such that $1 \leq i \leq 2^k$ . If there are several possible solutions, you can print any.
输入输出样例
输入 #1
2 0 1 2 3
输出 #1
Shi 2 0 1 3 2 1 3 0
输入 #2
2 0 0 0 0
输出 #2
Shi 0 1 2 3 0 1 2 3
输入 #3
2 0 1 2 2
输出 #3
Fou
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted