#abc288g. G - 3^N Minesweeper

G - 3^N Minesweeper

Score : 600600 points

问题描述

在位置 0,1,2,,3N10, 1, 2, \ldots, 3^N-1 上,可能存在0个或1个炸弹。
我们称位置 xxyy相邻 的,当且仅当对于每个 i=1,,Ni=1, \ldots, N 满足以下条件:

  • xx'yy' 分别表示 xxyy 在三进制表示下的第 ii 低位数,则有 xy1|x' - y'| \leq 1

已知在与位置 ii 相邻的位置上总共存在恰好 AiA_i 个炸弹。请打印出与该信息一致的炸弹布局。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

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

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

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

Constraints

  • 1N121 \leq N \leq 12
  • There is a placement of bombs consistent with A0,A1,,A3N1A_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:

NN

A0A_0 A1A_1 \ldots A3N1A_{3^N-1}

Output

Print B0,B1,,B3N1B_0, B_1, \ldots, B_{3^N-1} with spaces in between, where Bi=0B_i = 0 if position ii has no bomb and Bi=1B_i = 1 if position ii has a bomb.

Sample Input 1

1
0 1 1

Sample Output 1

0 0 1

Position 00 is neighboring positions 00 and 11, which have 00 bombs in total.
Position 11 is neighboring positions 00, 11, and 22, which have 11 bomb in total.
Position 22 is neighboring positions 11 and 22, which have 11 bombs in total.
If there is a bomb at only position 22, 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

update @ 2024/3/10 12:03:00