CF1168E.Xor Permutations

NOI/NOI+/CTSC

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Toad Mikhail has an array of 2k2^k integers a1,a2,…,a2ka_1, a_2, \ldots, a_{2^k}.

Find two permutations pp and qq of integers 0,1,…,2k−10, 1, \ldots, 2^k-1, such that aia_i is equal to pi⊕qip_i \oplus q_i for all possible ii, or determine there are no such permutations. Here ⊕\oplus denotes the bitwise XOR operation.

蟾蜍米哈伊尔有一个长度为 2k2^k 的整数数组 a1,a2,…,a2ka_1, a_2, \ldots, a_{2^k}。

请找出两个整数 0,1,…,2k−10, 1, \ldots, 2^k-1 的排列 pp 和 qq,使得对所有可能的 ii 均满足 ai=pi⊕qia_i = p_i \oplus q_i;若不存在这样的排列,则判定其不存在。此处 ⊕\oplus 表示按位异或运算。

输入格式

The first line contains one integer kk (2≤k≤122 \leq k \leq 12), denoting that the size of the array is 2k2^k.

The next line contains 2k2^k space-separated integers a1,a2,…,a2ka_1, a_2, \ldots, a_{2^k} (0≤ai<2k0 \leq a_i \lt 2^k) — the elements of the given array.

第一行包含一个整数 kk(2≤k≤122 \leq k \leq 12),表示数组的大小为 2k2^k。

第二行包含 2k2^k 个用空格分隔的整数 a1,a2,…,a2ka_1, a_2, \ldots, a_{2^k}(0≤ai<2k0 \leq a_i \lt 2^k)—— 给定数组的元素。

输出格式

If the given array can't be represented as element-wise XOR of two permutations of integers 0,1,…,2k−10, 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 2k2^k space-separated distinct integers p1,p2,…,p2kp_{1}, p_{2}, \ldots, p_{2^k}, and the second line should contain 2k2^k space-separated distinct integers q1,q2,…,q2kq_{1}, q_{2}, \ldots, q_{2^k}.

All elements of pp and qq should be between 00 and 2k−12^k - 1, inclusive; pi⊕qip_i \oplus q_i should be equal to aia_i for all ii such that 1≤i≤2k1 \leq i \leq 2^k. If there are several possible solutions, you can print any.

如果给定数组无法表示为两个整数排列 0,1,…,2k−10, 1, \ldots, 2^k-1 的按元素异或(XOR),则输出 "Fou"。

否则,在第一行输出 "Shi"。

接下来两行应分别描述两个满足条件的排列。第一行包含 2k2^k 个以空格分隔的互异整数 p1,p2,…,p2kp_{1}, p_{2}, \ldots, p_{2^k},第二行包含 2k2^k 个以空格分隔的互异整数 q1,q2,…,q2kq_{1}, q_{2}, \ldots, q_{2^k}。

pp 和 qq 的所有元素均应在 00 到 2k−12^k - 1(含端点)之间;且对所有满足 1≤i≤2k1 \leq i \leq 2^k 的 ii,需满足 pi⊕qi=aip_i \oplus q_i = a_i。若存在多种可行解,输出任意一种即可。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页