102886: [AtCoder]ABC288 G - 3^N Minesweeper

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

There is zero or one bomb at each of positions $0, 1, 2, \ldots, 3^N-1$.
Let us say that positions $x$ and $y$ are neighboring each other if and only if the following condition is satisfied for every $i=1, \ldots, N$.

  • Let $x'$ and $y'$ be the $i$-th lowest digits of $x$ and $y$ in ternary representation, respectively. Then, $|x' - y'| \leq 1$.

It is known that there are exactly $A_i$ bombs in total at the positions neighboring position $i$. Print a placement of bombs consistent with this information.

Constraints

  • $1 \leq N \leq 12$
  • There is a placement of bombs consistent with $A_0, A_1, \ldots, A_{3^N-1}$.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

$N$
$A_0$ $A_1$ $\ldots$ $A_{3^N-1}$

Output

Print $B_0, B_1, \ldots, B_{3^N-1}$ with spaces in between, where $B_i = 0$ if position $i$ has no bomb and $B_i = 1$ if position $i$ has a bomb.


Sample Input 1

1
0 1 1

Sample Output 1

0 0 1

Position $0$ is neighboring positions $0$ and $1$, which have $0$ bombs in total.
Position $1$ is neighboring positions $0$, $1$, and $2$, which have $1$ bomb in total.
Position $2$ is neighboring positions $1$ and $2$, which have $1$ bombs in total.
If there is a bomb at only position $2$, all conditions above are satisfied, so this placement is correct.


Sample Input 2

2
2 3 2 4 5 3 3 4 2

Sample Output 2

0 1 0 1 0 1 1 1 0

Sample Input 3

2
0 0 0 0 0 0 0 0 0

Sample Output 3

0 0 0 0 0 0 0 0 0

Input

题意翻译

位置 $0\sim 3^n-1$ 中有若干个雷,你需要找出这些雷,其中,每个位置至多有一个雷。 我们定义两个位置 $i$ 和 $j$ 是相邻的,当且仅当 $i$ 和 $j$ 在三进制表示下的每一位的差的绝对值都小于等于 $1$。(当然,自己也算与自己相邻) 现在,对于每一个位置 $i$,$A_i$ 表示与位置 $i$ 相邻的位置中雷的个数,请根据给定 $A$ 输出每个位置雷的个数。

Output

分数:$600$分

问题描述

在位置$0, 1, 2, \ldots, 3^N-1$中,有0个或1个炸弹。

我们说位置$x$和$y$是相邻的,当且仅当以下条件对所有$i=1, \ldots, N$都成立时。

  • 在三进制表示中,$x$和$y$的第$i$个最低位分别是$x'$和$y'$。那么,$|x' - y'| \leq 1$。

据知,在位置$i$相邻的位置上总共有$A_i$个炸弹。根据此信息打印炸弹的布置情况。

约束条件

  • $1 \leq N \leq 12$
  • 存在一个与$A_0, A_1, \ldots, A_{3^N-1}$一致的炸弹布置情况。
  • 输入中的所有值都是整数。

输入

输入数据从标准输入以以下格式给出:

$N$
$A_0$ $A_1$ $\ldots$ $A_{3^N-1}$

输出

用空格隔开地打印$B_0, B_1, \ldots, B_{3^N-1}$,其中如果位置$i$没有炸弹,则$B_i = 0$,如果位置$i$有炸弹,则$B_i = 1$。


样例输入1

1
0 1 1

样例输出1

0 0 1

位置$0$相邻的位置是$0$和$1$,它们总共有$0$个炸弹。

位置$1$相邻的位置是$0$、$1$和$2$,它们总共有$1$个炸弹。

位置$2$相邻的位置是$1$和$2$,它们总共有$1$个炸弹。

如果仅在位置$2$上有炸弹,则所有上述条件都得到满足,因此这个布置是正确的。


样例输入2

2
2 3 2 4 5 3 3 4 2

样例输出2

0 1 0 1 0 1 1 1 0

样例输入3

2
0 0 0 0 0 0 0 0 0

样例输出3

0 0 0 0 0 0 0 0 0

加入题单

算法标签: