C - 山崩し 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 8

注意

この問題に対する言及は、2020年5月2日 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。

試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

整数 2 \leq N \leq 50 に対して、縦 N マス、横 2N - 1 マスのマス目があります。

上から i 行目、左から j 列目のマスをマス (i, j) と表します。

このマス目は白黒の 2 色で 山型 に塗られています。具体的には、|j - N| < i を満たす 1 \leq i \leq N, 1 \leq j \leq (2N - 1) についてはマス (i, j) は黒く塗られており、他のマスは白く塗られています。

下は N = 5 の場合の例です。(# は黒く塗られたマス、. は白く塗られたマスを表します)

....#....
...###...
..#####..
.#######.
#########

ここで、黒く塗られたマスのうちいくつかに X を書きます。

書き込んだ後の状態は文字からなるサイズ N \times (2N - 1)2 次元配列 S として与えられ、S_{i, j} がマス (i, j) の状態を表します。S_{i, j}X のとき、マス (i, j)X の書かれた黒く塗られたマスであり、S_{i, j}# のとき、マス (i, j)X の書かれていない黒く塗られたマスであり、S_{i, j}. のとき、マス (i, j) は白く塗られたマスです。

それから、i = N - 1, N - 2, \cdots, 1 の順番で次の操作を行います。

  • 2 \leq j \leq 2N - 2 に対して、マス (i, j) が黒く塗られているが X は書かれておらず、マス (i+1, j-1), (i+1, j), (i+1, j+1) のうち 1 つ以上に X が書かれているとき、マス (i, j)X を書く。

全ての操作を終えた後のマス目の状態を計算してください。

制約

  • 2 \leq N \leq 50
  • S_{i, j}. または # または X
  • S に対応するマス目の状態は、山型に塗られたマス目の黒く塗られたマスのうち 1 つ以上に X を書くことで得られる

入力

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

N
S_{1,1}S_{i,2}\cdots S_{1,2N-1}
S_{2,1}S_{2,2}\cdots S_{2,2N-1}
:
S_{N,1}S_{N,2}\cdots S_{N,2N-1}

出力

全ての操作を終えた後のマス (i, j) の状態を T_{i,j} (黒かつ X が書かれているとき X、黒かつ X が書かれていないとき #、白のとき .) としたとき、以下の形式で出力せよ。

T_{1,1}T_{i,2}\cdots T_{1,2N-1}
T_{2,1}T_{2,2}\cdots T_{2,2N-1}
:
T_{N,1}T_{N,2}\cdots T_{N,2N-1}

入力例 1

5
....#....
...##X...
..#####..
.#X#####.
#########

出力例 1

....X....
...XXX...
..XX###..
.#X#####.
#########

入力例 2

2
.#.
#X#

出力例 2

.X.
#X#

入力例 3

10
.........#.........
........###........
.......#####.......
......#######......
.....#########.....
....###########....
...#############...
..###############..
.#################.
X#X########X#X####X

出力例 3

.........X.........
........XXX........
.......XXXXX.......
......XXXXXXX......
.....XXXXXXXXX.....
....XXXXXXXXXXX....
...XXX##XXXXXXXX...
..XXX####XXXXXXXX..
.XXX######XXXXX##X.
X#X########X#X####X

Score : 8 points

Warning

Do not make any mention of this problem until May 2, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded.

After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

We have an N \times (2N - 1) grid (N vertical, 2N - 1 horizontal) for an integer 1 \leq N \leq 50.

Let (i, j) denote the square at the i-th row from the top and j-th column from the left.

The squares are painted black and white so that the black part looks like a mountain. More specifically, for 1 \leq i \leq N and 1 \leq j \leq 2N - 1 such that |j - N| < i, (i, j) is painted black, and the other squares are painted white.

Below is the grid for the case N = 5. (# and . stand for a black square and a white square, respectively.)

....#....
...###...
..#####..
.#######.
#########

Now, we will write an X in some of the black squares.

The grid after this operation is given as a two-dimensional array of characters S of size N \times (2N - 1), where S_{i, j} corresponds to the square (i, j). If S_{i, j} is X, (i, j) is a black square with an X written on it; if S_{i, j} is #, (i, j) is a black square without an X written on it; if S_{i, j} is ., (i, j) is a white square.

Then, for each i = N - 1, N - 2, \cdots, 1 in this order, we will do the following operation:

  • For each 2 \leq j \leq 2N - 2, if (i, j) is painted black, has no X written on it, and at least one of the squares (i+1, j-1), (i+1, j), and (i+1, j+1) has X written in it, write X in (i, j)

Compute the final state of the grid after all the operations.

Constraints

  • 2 \leq N \leq 50
  • S_{i, j} is ., #, or X.
  • The state of the grid corresponding to S can be obtained by writing an X in one or more black squares in a grid painted black and white as described in Problem Statement.

Input

Input is given from Standard Input in the following format:

N
S_{1,1}S_{i,2}\cdots S_{1,2N-1}
S_{2,1}S_{2,2}\cdots S_{2,2N-1}
:
S_{N,1}S_{N,2}\cdots S_{N,2N-1}

Output

Output in the following format, where T_{i,j} is the character representing the state of the square (i, j) after all the operations. (T_{i,j} should be X if (i, j) is black and has an X written on it, # if (i, j) is black and has no X written on it, and . if (i, j) is white.)

T_{1,1}T_{i,2}\cdots T_{1,2N-1}
T_{2,1}T_{2,2}\cdots T_{2,2N-1}
:
T_{N,1}T_{N,2}\cdots T_{N,2N-1}

Sample Input 1

5
....#....
...##X...
..#####..
.#X#####.
#########

Sample Output 1

....X....
...XXX...
..XX###..
.#X#####.
#########

Sample Input 2

2
.#.
#X#

Sample Output 2

.X.
#X#

Sample Input 3

10
.........#.........
........###........
.......#####.......
......#######......
.....#########.....
....###########....
...#############...
..###############..
.#################.
X#X########X#X####X

Sample Output 3

.........X.........
........XXX........
.......XXXXX.......
......XXXXXXX......
.....XXXXXXXXX.....
....XXXXXXXXXXX....
...XXX##XXXXXXXX...
..XXX####XXXXXXXX..
.XXX######XXXXX##X.
X#X########X#X####X