#P8242. Framed Crossword Puzzle

    ID: 21421 Type: Default 1000ms 256MiB

Framed Crossword Puzzle

Framed Crossword Puzzle

Mirko created an ingenious crossword puzzle which can be visualized as an ( m \times n ) grid, each cell containing a lowercase letter. He now wishes to frame the puzzle with a border. The border widths on the top, left, right, and bottom are given by ( u ), ( l ), ( r ), and ( d ) respectively. The border itself is partitioned into cells, each of which is either a # or a .. Moreover, when the frame completely covers the puzzle area, the top‐left cell of the framed grid must be a #, and any two adjacent cells (sharing a side) must contain different characters.

Of course, if a cell originally belongs to the crossword puzzle then its letter is retained in the final framed output (i.e. it is not overridden by a border character).

Your task is to output the final grid after adding the frame. The final grid dimensions become ( (u + m + d) ) rows and ( (l + n + r) ) columns. For any cell in the border (i.e. not part of the original puzzle), assign a character according to an alternating pattern starting from the top‐left cell: if the sum of the row index and column index is even, place a #, otherwise place a ..

inputFormat

The first line contains six integers: ( m ), ( n ), ( u ), ( l ), ( r ), ( d ) where ( m ) and ( n ) represent the dimensions of the crossword puzzle, and ( u ), ( l ), ( r ), ( d ) denote the border widths (top, left, right, bottom) respectively.

This is followed by ( m ) lines, each a string of length ( n ) consisting of lowercase letters, representing the puzzle.

outputFormat

Output the final framed grid, consisting of ( u+m+d ) rows and ( l+n+r ) columns. Each row should be printed as a string. Cells that belong to the border should be filled using an alternating pattern (starting with # at the top-left and alternating so that adjacent cells have different characters), while cells belonging to the original puzzle should retain their letter.

sample

2 2 1 1 1 1
ab
cd
#.#.

.ab# #cd. .#.#

</p>