#4539. 3^N Minesweeper

0

3^N Minesweeper

3^N Minesweeper

题目描述

There is zero or one bomb at each of positions 0,1,2,…,3N−10, 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 x′x' and y′y' be the ii-th lowest digits of xx and yy in ternary representation, respectively. Then, ∣x′−y′∣≤1|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.

输入格式

The input is given from Standard Input in the following format: NN A0A_0 A1A_1 …\ldots A3N−1A_{3^N-1}

输出格式

Print B0,B1,…,B3N−1B_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.

1
0 1 1
0 0 1
2
2 3 2 4 5 3 3 4 2
0 1 0 1 0 1 1 1 0
2
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

提示

1≤N≤121 \leq N \leq 12 There is a placement of bombs consistent with A0,A1,…,A3N−1A_0, A_1, \ldots, A_{3^N-1}. All values in the input are integers.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.

标签: AtCoder|abc288G

来源

AtCoder|abc288G