B - Creating Mosaic Art Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 266

問題文

高橋君は文化祭でモザイクアートを作ることになりました。

まず、高橋君は HW 列のグリッド状のデザイン原案を用意しました。グリッドの各マスは #(塗りつぶし)または .(空白)のいずれかです。

高橋君はこのデザイン原案をもとに、以下の手順でモザイクアートを作成します。

手順 1:拡大

デザイン原案を縦横それぞれ K 倍に拡大します。すなわち、原案の各マスを KK 列の同じ文字のブロックに置き換えることで、#. からなる (H \times K)(W \times K) 列のグリッドを得ます。

手順 2:文字の割り当て

手順 1 で得られた (H \times K)(W \times K) 列のグリッドにおいて、# をすべて文字 c_1 に、. をすべて文字 c_2 にそれぞれ置き換えます。ここで c_1c_2 はそれぞれ英小文字 (az) または英大文字 (AZ) のいずれか 1 文字です。c_1c_2 が同じ文字である場合もあります。

最終的に得られる (H \times K)(W \times K) 列のモザイクアートを出力してください。

制約

  • 1 \leq H \leq 100
  • 1 \leq W \leq 100
  • 1 \leq K \leq 50
  • H, W, K はいずれも整数
  • c_1 は英小文字 (az) または英大文字 (AZ) のいずれか 1 文字
  • c_2 は英小文字 (az) または英大文字 (AZ) のいずれか 1 文字
  • c_1c_2 は同じ文字であることもある
  • S_i#. からなる長さ W の文字列

入力

H W K
c_1 c_2
S_1
S_2
\vdots
S_H
  • 1 行目には、デザイン原案の行数 H、列数 W、拡大倍率 K が空白区切りで与えられる。
  • 2 行目には、# の代わりに使う文字 c_1. の代わりに使う文字 c_2 が空白区切りで与えられる。
  • 続く H 行にわたって、デザイン原案が与えられる。そのうち i 番目 (1 \leq i \leq H) の行には、デザイン原案の上から i 行目に対応する文字列 S_i が与えられる。S_i#. からなる長さ W の文字列である。

出力

最終的に得られるモザイクアートを (H \times K) 行にわたって出力せよ。各行は長さ (W \times K) の文字列である。


入力例 1

3 3 2
X o
#.#
.#.
#.#

出力例 1

XXooXX
XXooXX
ooXXoo
ooXXoo
XXooXX
XXooXX

入力例 2

2 4 3
A B
#..#
.##.

出力例 2

AAABBBBBBAAA
AAABBBBBBAAA
AAABBBBBBAAA
BBBAAAAAABBB
BBBAAAAAABBB
BBBAAAAAABBB

入力例 3

5 6 4
R w
#....#
.#..#.
..##..
.#..#.
#....#

出力例 3

RRRRwwwwwwwwwwwwwwwwRRRR
RRRRwwwwwwwwwwwwwwwwRRRR
RRRRwwwwwwwwwwwwwwwwRRRR
RRRRwwwwwwwwwwwwwwwwRRRR
wwwwRRRRwwwwwwwwRRRRwwww
wwwwRRRRwwwwwwwwRRRRwwww
wwwwRRRRwwwwwwwwRRRRwwww
wwwwRRRRwwwwwwwwRRRRwwww
wwwwwwwwRRRRRRRRwwwwwwww
wwwwwwwwRRRRRRRRwwwwwwww
wwwwwwwwRRRRRRRRwwwwwwww
wwwwwwwwRRRRRRRRwwwwwwww
wwwwRRRRwwwwwwwwRRRRwwww
wwwwRRRRwwwwwwwwRRRRwwww
wwwwRRRRwwwwwwwwRRRRwwww
wwwwRRRRwwwwwwwwRRRRwwww
RRRRwwwwwwwwwwwwwwwwRRRR
RRRRwwwwwwwwwwwwwwwwRRRR
RRRRwwwwwwwwwwwwwwwwRRRR
RRRRwwwwwwwwwwwwwwwwRRRR

Score : 266 pts

Problem Statement

Takahashi is going to create mosaic art for the school festival.

First, Takahashi prepared a design draft in the form of a grid with H rows and W columns. Each cell of the grid is either # (filled) or . (blank).

Based on this design draft, Takahashi creates the mosaic art using the following procedure.

Step 1: Enlargement

Enlarge the design draft by a factor of K both vertically and horizontally. Specifically, replace each cell of the draft with a block of K rows and K columns filled with the same character, obtaining a grid of (H \times K) rows and (W \times K) columns consisting of # and ..

Step 2: Character Assignment

In the (H \times K) by (W \times K) grid obtained in Step 1, replace all # with character c_1 and all . with character c_2. Here, c_1 and c_2 are each a single character that is either a lowercase English letter (az) or an uppercase English letter (AZ). It is possible that c_1 and c_2 are the same character.

Output the resulting mosaic art of (H \times K) rows and (W \times K) columns.

Constraints

  • 1 \leq H \leq 100
  • 1 \leq W \leq 100
  • 1 \leq K \leq 50
  • H, W, K are all integers
  • c_1 is a single character that is either a lowercase English letter (az) or an uppercase English letter (AZ)
  • c_2 is a single character that is either a lowercase English letter (az) or an uppercase English letter (AZ)
  • c_1 and c_2 may be the same character
  • S_i is a string of length W consisting of # and .

Input

H W K
c_1 c_2
S_1
S_2
\vdots
S_H
  • The first line contains the number of rows H, the number of columns W, and the enlargement factor K of the design draft, separated by spaces.
  • The second line contains the character c_1 to replace # and the character c_2 to replace ., separated by a space.
  • Over the following H lines, the design draft is given. The i-th (1 \leq i \leq H) of these lines contains the string S_i corresponding to the i-th row from the top of the design draft. S_i is a string of length W consisting of # and ..

Output

Output the resulting mosaic art over (H \times K) lines. Each line is a string of length (W \times K).


Sample Input 1

3 3 2
X o
#.#
.#.
#.#

Sample Output 1

XXooXX
XXooXX
ooXXoo
ooXXoo
XXooXX
XXooXX

Sample Input 2

2 4 3
A B
#..#
.##.

Sample Output 2

AAABBBBBBAAA
AAABBBBBBAAA
AAABBBBBBAAA
BBBAAAAAABBB
BBBAAAAAABBB
BBBAAAAAABBB

Sample Input 3

5 6 4
R w
#....#
.#..#.
..##..
.#..#.
#....#

Sample Output 3

RRRRwwwwwwwwwwwwwwwwRRRR
RRRRwwwwwwwwwwwwwwwwRRRR
RRRRwwwwwwwwwwwwwwwwRRRR
RRRRwwwwwwwwwwwwwwwwRRRR
wwwwRRRRwwwwwwwwRRRRwwww
wwwwRRRRwwwwwwwwRRRRwwww
wwwwRRRRwwwwwwwwRRRRwwww
wwwwRRRRwwwwwwwwRRRRwwww
wwwwwwwwRRRRRRRRwwwwwwww
wwwwwwwwRRRRRRRRwwwwwwww
wwwwwwwwRRRRRRRRwwwwwwww
wwwwwwwwRRRRRRRRwwwwwwww
wwwwRRRRwwwwwwwwRRRRwwww
wwwwRRRRwwwwwwwwRRRRwwww
wwwwRRRRwwwwwwwwRRRRwwww
wwwwRRRRwwwwwwwwRRRRwwww
RRRRwwwwwwwwwwwwwwwwRRRR
RRRRwwwwwwwwwwwwwwwwRRRR
RRRRwwwwwwwwwwwwwwwwRRRR
RRRRwwwwwwwwwwwwwwwwRRRR