G - 3^N Minesweeper Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

位置 0, 1, 2, \ldots, 3^N-1 にそれぞれ 0 個あるいは 1 個の爆弾があります。
また、位置 x と位置 yi=0,1, \ldots, N-1 すべてに対し以下の条件を満たすとき、またそのときに限り近い位置であるとします。

  • x, y3 進表記したときの 3^i の位の数字をそれぞれ x', y' として、|x' - y'| \leq 1 が成立する。

位置 i と近い位置にある爆弾の個数が A_i 個であるとわかっているとき、爆弾の配置としてありえるものを 1 つ出力してください。

制約

  • 1 \leq N \leq 12
  • A_0, A_1, \ldots, A_{3^N-1} に対応する爆弾の配置が存在する
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

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

出力

位置 i に爆弾がないとき B_i = 0 、位置 i に爆弾があるとき B_i = 1 として B_0, B_1, \ldots, B_{3^N-1} を空白区切りで出力せよ。


入力例 1

1
0 1 1

出力例 1

0 0 1

0 と近い位置は 01 で、位置 0 と位置 1 に爆弾は合計で 0 個あります。
1 と近い位置は 012 で、位置 0 と位置 1 と位置 2 に爆弾は合計で 1 個あります。
2 と近い位置は 12 で、位置 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

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