/
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
縦 H 行、横 W 列 のマス目があります。 高橋くんは、このマス目のそれぞれのマスを白か黒で塗ろうとしています。
高橋くんは、マス目に含まれるマスのうち端にあるマスをすべて黒く塗り、それ以外のマスを白く塗ります。 高橋くんが色を塗ったあとのマス目を出力してください。
より厳密には
H\times W のマス目があります。
上から i 行目 (1\le i\le H) 、左から j 列目 (1\le j\le W) のマスをマス (i,j) と呼ぶことにします。
マス (i,j)\ (1\le i\le H,1\le j\le W) とマス (k,l)\ (1\le k\le H,1\le l\le W) が |i-k|+|j-l|=1 を満たすとき、かつそのときに限りこれらのマスは辺で隣接していると言います。
マス (i,j) と辺で隣接しているマスが 3 個以下のとき、かつそのときに限りマス (i,j) は端にあると言います。
次の条件を満たす H 個の文字列 S _ 1,S _ 2,\ldots,S _ H を求めてください。
- S _ i は長さ W の文字列であり、S _ i の j 文字目は、マス (i,j) が端にあるとき
#、そうでないとき.である。
制約
- 3\le H\le10
- 3\le W\le10
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
H W
出力
H 行にわたって、長さ W の文字列を出力せよ。
i 行目 (1\le i\le H) の j 文字目 (1\le j\le W) には、マス (i,j) が黒く塗られているなら # 、白く塗られているなら . を出力せよ。
入力例 1
4 5
出力例 1
##### #...# #...# #####
例えば、マス (1,1) は端にあります。
マス (1,1) と辺で隣接しているマスはマス (1,2) とマス (2,1) の 2 個のみだからです。
よって、マス (1,1) は黒く塗られるので、1 行目の 1 文字目には # を出力してください。
逆に、例えばマス (3,4) は端にありません。
マス (3,4) と辺で隣接しているマスはマス (2,4), マス (3,3), マス (3,5), マス (4,4) の 4 個だからです。
よって、マス (3,4) は白く塗られるので、3 行目の 4 文字目には . を出力してください。
入力例 2
5 6
出力例 2
###### #....# #....# #....# ######
Score : 200 points
Problem Statement
There is a grid with H rows and W columns. Takahashi is going to paint each cell of this grid black or white.
He paints all cells on the border of the grid black, and all other cells white. Output the grid after he has painted it.
More formally
There is an H\times W grid.
We call the cell at the i-th row from the top (1\le i\le H) and the j-th column from the left (1\le j\le W) cell (i,j).
Cell (i,j)\ (1\le i\le H,1\le j\le W) and cell (k,l)\ (1\le k\le H,1\le l\le W) are said to be edge-adjacent if and only if |i-k|+|j-l|=1.
Cell (i,j) is said to be on the border if and only if the number of cells edge-adjacent to cell (i,j) is at most 3.
Find H strings S _ 1,S _ 2,\ldots,S _ H satisfying the following condition.
- S _ i is a string of length W, and the j-th character of S _ i is
#if cell (i,j) is on the border, and.otherwise.
Constraints
- 3\le H\le10
- 3\le W\le10
- All input values are integers.
Input
The input is given from Standard Input in the following format:
H W
Output
Output H lines, each a string of length W.
The j-th character (1\le j\le W) of the i-th line (1\le i\le H) should be # if cell (i,j) is painted black, and . if it is painted white.
Sample Input 1
4 5
Sample Output 1
##### #...# #...# #####
For example, cell (1,1) is on the border.
This is because there are only two cells edge-adjacent to cell (1,1): cells (1,2) and (2,1).
Thus, cell (1,1) is painted black, so the first character of the first line should be #.
Conversely, for example, cell (3,4) is not on the border.
This is because there are four cells edge-adjacent to cell (3,4): cells (2,4), (3,3), (3,5), and (4,4).
Thus, cell (3,4) is painted white, so the fourth character of the third line should be ..
Sample Input 2
5 6
Sample Output 2
###### #....# #....# #....# ######