Problem:


Score : 200 points

Problem Statement

You are given an H × W grid.

The squares in the grid are described by H strings, S_1,...,S_H.

The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).

. stands for an empty square, and # stands for a square containing a bomb.  

Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.

(Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)

He decides to replace each . in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.  

Print the strings after the process.  

Constraints

1 \leq H,W \leq 50

S_i is a string of length W consisting of # and ..

Input

Input is given from Standard Input in the following format:  

H W
S_1
:
S_H

Output

Print the H strings after the process.

The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W).  

Sample Input 1

3 5
.....
.#.#.
.....

Sample Output 1

11211
1#2#1
11211

For example, let us observe the empty square at the first row from the top and first column from the left.

There is one bomb square adjacent to this empty square: the square at the second row and second column.

Thus, the . corresponding to this empty square is replaced with 1.  

Sample Input 2

3 5
#####
#####
#####

Sample Output 2

#####
#####
#####

It is possible that there is no empty square.  

Sample Input 3

6 6
#####.
#.#.##
####.#
.#..#.
#.##..
#.#...

Sample Output 3

#####3
#8#7##
####5#
4#65#2
#5##21
#4#310



Sample input:
3 5
.....
.#.#.
.....


Sample output:
11211
1#2#1
11211

Submission status: Wrong Answer

Solution code:
H, W = list(map(int, input().split()))
rows = [input() for i in range(H)]
grid = [list(row) for row in rows]


'''generating a grid expanded by '&'. For example,

            &&&&&
#.#         &#.#&
###    ->   &###&
##.         &##.& 
            &&&&&

'''

expanded_grid = [list('&' * (W + 2))]
for row in rows:
    expanded_grid.append(list('&' + row + '&'))
expanded_grid.append(list('&' * (W + 2)))

for i in range(H):
    for j in range(W):
        if (grid[i])[j] == '.':
            EightPiece = [
                (expanded_grid[i])[j],
                (expanded_grid[i])[j+1],
                (expanded_grid[i])[j + 2],

                (expanded_grid[i+1])[j],
                (expanded_grid[i])[j+2],

                (expanded_grid[i+2])[j],
                (expanded_grid[i+2])[j],
                (expanded_grid[i+2])[j],
            ]

            (grid[i])[j] = str(EightPiece.count('#'))

for row_in_the_form_of_list in grid:
    print(''.join(row_in_the_form_of_list))

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
a=[[0 if s=="." else "#" for s in list(input())] for i in range(h)]
for _ in range(h):
  for s in range(w):
    if a[_][s]=="#":
      try:
        a[_-1][s]+=1
      except:
        continue
      try:
        a[_+1][s]+=1
      except:
        continue
      try:
        a[_][s-1]+=1
      except:
        continue
      try:
        a[_][s+1]+=1
      except:
        continue
      try:
        a[_+1][s+1]+=1
      except:
        continue
      try:
        a[_+1][s-1]+=1
      except:
        continue
      try:
        a[_-1][s+1]+=1
      except:
        continue
      try:
        a[_-1][s-1]+=1
      except:
        continue
    print(a)
for s in range(h):
  print(a[s])

Submission status: Wrong Answer

Solution code:
H, W = map(int,input().split())
S = [input() for _ in range(H)]

result = [[0 for _ in range(W+1)]for _ in range(H+1)]
for i in range(H):
  for j in range(W):
    if(S[i][j] == '#'):
      result[i][j] = '#'
      if(result[i-1][j-1] != '#'):
        result[i-1][j-1] += 1
      if(result[i-1][j] != '#'):
        result[i-1][j] += 1
      if(result[i-1][j+1] != '#'):
        result[i-1][j+1] += 1
      if(result[i][j-1] != '#'):
        result[i][j-1] += 1
      if(result[i][j+1] != '#'):
        result[i][j+1] += 1
      if(result[i+1][j-1] != '#'):
        result[i+1][j-1] += 1
      if(result[i+1][j] != '#'):
        result[i+1][j] += 1
      if(result[i+1][j+1] != '#'):
        result[i+1][j+1] += 1

for r in result[:-1]:
  print(''.join(list(map(str,r[:H]))))

Submission status: Wrong Answer

Solution code:
H, W = map(int,input().split())
S = [input() for _ in range(H)]

result = [[0 for _ in range(W+1)]for _ in range(H+1)]
for i in range(H):
  for j in range(W):
    if(S[i][j] == '#'):
      result[i][j] = '#'
      if(result[i-1][j-1] != '#'):
        result[i-1][j-1] += 1
      if(result[i-1][j] != '#'):
        result[i-1][j] += 1
      if(result[i-1][j+1] != '#'):
        result[i-1][j+1] += 1
      if(result[i][j-1] != '#'):
        result[i][j-1] += 1
      if(result[i][j+1] != '#'):
        result[i][j+1] += 1
      if(result[i+1][j-1] != '#'):
        result[i+1][j-1] += 1
      if(result[i+1][j] != '#'):
        result[i+1][j] += 1
      if(result[i+1][j+1] != '#'):
        result[i+1][j+1] += 1

for r in result[:-1]:
  ''.join(list(map(str,r[:H])))

Submission status: Wrong Answer

Solution code:
def check(arr, x, y):
    d = ((0, -1), (0, 1), (1, -1), (1, 0), (1, 1), (-1, -1), (-1, 0), (-1, 1))

    if arr[x][y] == '#':
        return -1
    else:
        cnt = 0
        for dx, dy in d:
            try:
                if arr[x + dx][y + dy] == '#':
                    cnt += 1
            except:
                pass
    return cnt    

h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(input())
ans = []
for x in range(h):
    for y in range(w):
        val = check(s, x, y)
        if val == -1:
            ans.append('#')
        else:
            ans.append(val)

for i in range(h*w):
    print(ans[i], end="")
    if (i+1)%w == 0:
        print()

Submission status: Wrong Answer

Solution code:
import copy
y,x = map(int,input().split())
maps = []


def ccc(i,x,maps):
    l = []
    try:
        l.append(maps[i-1][x-1])
    except:

        pass
    try:
        l.append(maps[i-1][x])
    except:
        pass
    try:
        l.append(maps[i-1][x+1])
        
    except:
        pass
    try:
        l.append(maps[i][x-1])
        
    except:

        pass
    try:
        l.append(maps[i][x+1])
        
    except:

        pass
    try:
        l.append(maps[i+1][x-1])
        
    except:

        pass
    try:
        l.append(maps[i+1][x])   
        
    except:

        pass
    try:
        l.append(maps[i+1][x+1])
        
    except:

        pass

    return l


for i in range(y):
    s = str(input())
    maps.append([s[i] for i in range(x)])
maps2 = copy.deepcopy(maps)
for i in range(y):
    for j in range(x):
        r = maps[i][j]
        ll = ccc(i,j,maps)

        if r == ".":
            k = ll.count("#")
            maps2[i][j] = str(k)

for i in range(y):
    print(''.join(maps2[i]))

Submission status: Wrong Answer

Solution code:
int_h, int_w = map(int, input().split())
l_h = list()
for i in range(int_h):
    l_h.append(input())

l_temp = list()
l_temp.append(list(map(int, "0" * (int_w + 2))))
for r in l_h:
    l_temp.append(list(map(lambda x: int(x) if x != "#" else x, "0" + r.replace(".", "0") + "0")))

l_temp.append(list(map(int, "0" * (int_w + 2))))


print(l_temp)


for rownum, row in enumerate(l_temp):
    for colnum, col in enumerate(row):
        if col == "#":
            for c in [-1, 0, 1]:
                if l_temp[rownum - 1][colnum + c] != "#":
                    l_temp[rownum - 1][colnum + c] += 1
                if l_temp[rownum + 1][colnum + c] != "#":
                    l_temp[rownum + 1][colnum + c] += 1
            for c in [-1, 1]:
                if l_temp[rownum][colnum + c] != "#":
                    l_temp[rownum][colnum + c] += 1


for row in l_temp[1:-1]:
    print("".join(map(str,row[1:-1])))

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
S = [input() for i in range(h)]
print(S[0:2])
for i in range(h):
    l = ''
    for j in range(w):
        if S[i][j] == '#':
            l += '#'
        else:
            l += str(sum([T[max(0, j-1) : min(w, j+2)].count('#') for T in S[max(0, i-1) : min(h, i+2)]]))
    print(l)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
a = [input() for w in range(h)]

for i in range(h)[::-1]:
    if "#" not in a[i]:
        del a[i]
        h -= 1

n = []
for j in range(w):
    m = ["".join(t[j] for t in a)]
    if "#" in m[0]:
        n += m

for k in range(h):
    print("".join(u[k] for u in n))

Submission status: Wrong Answer

Solution code:
def main():
    h, w = map(int, input().split())
    b = []
    for _ in range(h):
        b.append(input())

    # b[1][1] -> b[0][0], b[0][1], b[0][2], b[1][0], b[1][2], b[2][0], b[2][1], b[2][2]

    ans = []
    for i in range(h):
        e = []
        for j in range(w):
            e.append(0)
        ans.append(e)

    for i in range(h):
        for j in range(w):
            count = 0
            v = b[i][j]
            if v == "#":
                ans[i][j] = '#'
                continue

            for k in range(-1, 2):
                for l in range(-1, 2):
                    if i + k < 0 or i + k >= h:
                        pass
                    elif j + l < 0 or j + l >= w:
                        pass
                    else:
                        if b[i + k][j + l] == "#":
                            count += 1
            ans[i][j] = count

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
m = [input() for _ in range(h)]

for i in range(h):
    string = ''
    for j in range(w):
        if m[i][j] == '#':
            string += '#'
        else:
            string+= str(sum([t[max(0,j-1):min(w,j+2)].count('#') for t in m[max(0,i-1):min(h,j+2)]]))
            
    print(string)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
m = [input() for _ in range(h)]

for i in range(h):
    string = ''
    for j in range(w):
        if m[i][j] == '#':
            string += '#'
        else:
            string+= str(sum(t[max(0,j-1):min(w,j+2)].count('#') for t in m[max(0,i-1):min(h,j+2)]))
    print(string)

Submission status: Wrong Answer

Solution code:
import numpy as np

H, W = map(int, input().split(' '))

in_table = []
for h in range(H):
    line = [c for c in input()]    
    in_table.append(line)

result_table = np.zeros((H, W), dtype=np.int8)
for y, line in enumerate(in_table):
    for x, cell in enumerate(line):
        if cell == '#':
            result_table[y-1:y+1+1, x-1:x+1+1] += 1
            result_table[y][x] = -1

for line in result_table.astype(str):
    for cell in line:
        if cell == '-1':
            print('#', end='')
        else:
            print(cell, end='')
    print('')

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
s = [input() for _ in range(h)]

for i in range(h):
    l = ''
    for j in range(w):
        if s[i][j] == '#':
            l += s[i][j]
        else:
            l += str(sum([t[max(0,j-1):min(j+2,w)].count('#')\
                     for t in s[max(0,i):min(h,i+2)]]))
    print(l)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
board = [list(input()) for _ in range(h)]
dx = [-1, 0, 1, -1, 1, -1, 0, 1]
dy = [-1, -1, -1, 0, 0, 1, 1, 1]
for i in range(h):
    for j in range(w):
        if board[i][j] is '.':
            board[i][j] = 0
            for k in range(8):
                try:
                    board[i][j] += 1 if board[i + dy[k]][j + dx[k]] is '#' else 0
                except IndexError:
                    pass
for s in board:
    print(''.join(map(str, s)))

Submission status: Wrong Answer

Solution code:
g,r=map(int,input().split())
A=["."*(r+2)]
for i in range(g):
    w="."+input()+"."
    A.append(w)
A.append("."*(r+2))
for i in range(1,g+1):
    for j in range(1,r+1):
        if A[i][j]==".":
            B=[]
            for m in [i-1,i,i+1]:
                for k in [j-1,j,j+1]:
                    B.append(A[m][k])
                    A[i]=A[i][1:r+1:].replace(".",str(B.count("#")),1)
                    A[i]="."+A[i]+"."
for i in range(1,g+1):
    print(A[i][1:r+1:])

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [0] * h
for i in range(h):
    s[i] = str(input())
t = [[0]*w]*h

if h == 1 and w == 1:
    if s[0][0] == '#':
        v = '#'
    else:
        v = 0
    t[0][0] = str(v)
    print(''.join(t[0]))
    
elif h ==1 and w !=1:
    for k in range(w):
        if k == 0:
            u = s[0][1]
        elif k == w-1:
            u = s[0][k-1]
        else:
            u = s[0][k-1] +s[0][k+1]
        v = u.count('#')
        if s[0][k] == '#':
            v = '#'
        t[0][k] = str(v)
    print(''.join(t[0]))

elif h !=1 and w == 1:
    for j in range(h):
        if j == 0:
            u = s[1][0]
        elif j == h-1:
            u = s[j-1][0]
        else:
            u = s[j-1][0] + s[j+1][0]
        if s[j][0] == '#':
            v = '#'
        t[j][0] = str(v)
        print(''.join(t[j]))

else:
    for j in range(h):
        if j == 0:
            for k in range(w):
                if k == 0:
                    u = s[0][1] + s[1][0] + s[1][1]
                elif k == w-1:
                    u = s[0][k-1] +s[1][k-1] + s[1][k]
                else:
                    u = s[0][k-1] +s[0][k+1] + s[1][k-1] + s[1][k] + s[1][k+1]
                v = u.count('#')
                if s[j][k] == '#':
                    v = '#'
                t[j][k] = str(v)
        elif j == h-1:
            for k in range(w):
                if k == 0:
                    u = s[j][1] + s[j-1][0] + s[j-1][1]
                elif k == w-1:
                    u = s[j][k-1] +s[j-1][k-1] + s[j-1][k]
                else:
                    u = s[j][k-1] +s[j][k+1] + s[j-1][k-1] + s[j-1][k] + s[j-1][k+1]
                v = u.count('#')
                if s[j][k] == '#':
                    v = '#'
                t[j][k] = str(v)
        else:
             for k in range(w):
                if k == 0:
                    u = s[j][1] + s[j-1][0] + s[j-1][1] + s[j+1][0] + s[j+1][1]
                elif k == w-1:
                    u = s[j][k-1] +s[j-1][k-1] + s[j-1][k] + s[j+1][k-1] + s[j+1][k]
                else:
                    u = s[j][k-1] +s[j][k+1] + s[j-1][k-1] + s[j-1][k] + s[j-1][k+1] + s[j+1][k-1] + s[j+1][k] + s[j+1][k+1]
                v = u.count('#')
                if s[j][k] == '#':
                    v = '#'
                t[j][k] = str(v)
        print(''.join(t[j]))

Submission status: Wrong Answer

Solution code:
g,r=map(int,input().split())
A=["."*(r+2)]
for i in range(g):
  w="."+input()+"."
  A.append(w)
A.append("."*(r+2))
print(A)
for i in range(1,g+1):
  for j in range(1,r+1):
    if A[i][j]==".":
      B=[]
      for m in [i-1,i,i+1]:
        for k in [j-1,j,j+1]:
          B.append(A[m][k])
      print(B)
      print(B.count("#"))
      A[i]=A[i][1:r+1:].replace(".",str(B.count("#")),1)
      A[i]="."+A[i]+"."
for i in range(1,g+1):
  print(A[i][1:r+1:])

Submission status: Wrong Answer

Solution code:
# coding: utf-8
H, W = map(int, input().split())

# 一回り大きい並びになるように、"." をパディングする
lst = ["."*(W+2)] + ["." + input() + "." for _ in range(H)] + ["."*(W+2)]
print(lst)

# lst と同じ形で、要素が全部 0 のリスト
# lst2 = [[0]*(W+2)] * (H+2)  # この作り方はダメ。http://delta114514.hatenablog.jp/entry/2018/01/02/233002
lst2 = []
for _ in range(H+2):
    lst2.append([0 for _ in range(W+2)])

# パディングの内側を3x3の窓で、「. の周囲に # があるか」探索する
for i in range(1, H+1):
    for j in range(1, W+1):
        cnt = 0
        if lst[i][j] == ".":
            cnt += lst[i-1][j-1:j+2].count("#")
            cnt += lst[i][j-1:j+2].count("#")
            cnt += lst[i+1][j-1:j+2].count("#")
            lst2[i][j] = str(cnt)
        else:
            lst2[i][j] = "#"

for i in range(1, H+1):
    print("".join(lst2[i][1:W+1]))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
H, W = map(int, input().split())

# 一回り大きい並びになるように、"." をパディングする
lst = ["."*(W+2)] + ["." + input() + "." for _ in range(H)] + ["."*(W+2)]
print(lst)

# lst と同じ形で、要素が全部 0 のリスト
lst2 = []
for _ in range(H+2):
    lst2.append([0 for _ in range(W+2)])

# パディングの内側を3x3の窓で、「. の周囲に # があるか」探索する
for i in range(1, H+1):
    for j in range(1, W+1):
        cnt = 0
        if lst[i][j] == ".":
            cnt += lst[i-1][j-1:j+2].count("#")
            cnt += lst[i][j-1:j+2].count("#")
            cnt += lst[i+1][j-1:j+2].count("#")
            lst2[i][j] = str(cnt)
        else:
            lst2[i][j] = "#"

for i in range(1, H+1):
    print("".join(lst2[i][1:W+1]))

Submission status: Wrong Answer

Solution code:
'''TODO:カウント関連直す'''

h,w = map(int,input().split())
board = [input() for _ in range(h)]
dx = [-1,-1,-1, 0,0, 1,1,1]
dy = [-1, 0, 1,-1,1,-1,0,1]
ans_board = [[0 for _ in range(w)] for _ in range(h)]

for x in range(h):
    cnt = 0
    for y in range(w):
        if board[x][y] == '#':
            ans_board[x][y] = '#'
        else:
            for d in range(len(dx)):
                n_x = x+dx[d]
                n_y = y+dy[d]

                if 0 < n_x <= h or 0 < n_y <= w:
                    continue
                elif board[n_x][n_y] == '#':
                    cnt += 1
            ans_board[x][y] = str(cnt)

for ans in ans_board:
    print('' .join(ans))

Submission status: Wrong Answer

Solution code:
import itertools
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
l=list(itertools.product([-1,0,1],repeat=2))

for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            cnt = 0
            for k in l:
                x = min(max(0,i+k[0]),h-1)
                y = min(max(0,j+k[1]),w-1)
                if s[x][y]=='#':
                    cnt+=1
            s[i][j]=str(cnt)
for i in s:
    print(''.join(i))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
MAP = [input() for i in range(H)]
NUM = [[0 for i in range(W)] for j in range(H)]

for i in range(H):
    for j in range(W):
        if MAP[i][j] == '#':
            if i != 0 and j != 0:
                NUM[i-1][j-1] += 1
                NUM[i-1][j] += 1
                NUM[i][j-1] += 1
            if i != 0 and j != W-1:
                NUM[i-1][j+1] += 1
                NUM[i][j+1] += 1
            if i != H-1 and j != 0:
                NUM[i+1][j-1] += 1
                NUM[i+1][j] += 1
            if i != H-1 and j != W-1:
                NUM[i+1][j+1] += 1
for i in range(H):
    for j in range(W):
        if MAP[i][j] == '#':
            NUM[i][j] = '#'
    else:
        print(''.join(map(str, NUM[i])))

Submission status: Wrong Answer

Solution code:
[ height , width ] = list(map(int,input().split()))

input_map = []
output_map = [[0 for j in range(width)] for i in range(height)]

def is_sharp( input_map , x, y , width , height):
	if( x==-1 or y == -1 or x+1 >= width or y+1 >= height  ) :return 0
	
	if( input_map[y][x] == '#'):
		return 1
	else:
		 return 0

def count_sharp_num( input_map , x , y):
	count = 0
	count += is_sharp(input_map , x-1 , y-1 , width , height)
	count += is_sharp(input_map , x-1 , y , width , height)
	count += is_sharp(input_map , x-1 , y+1 , width , height)
	count += is_sharp(input_map , x , y-1 , width , height)
	count += is_sharp(input_map , x , y+1 , width , height)
	count += is_sharp(input_map , x+1 , y-1 , width , height)
	count += is_sharp(input_map , x+1 , y , width , height)
	count += is_sharp(input_map , x+1 , y+1 , width , height)
	return count

for i in range( height ):
	input_map.append( input() )


for x in range( width ):
	for y in range( height ):
		output_map[y][x] = count_sharp_num(input_map,x,y)
		if input_map[y][x] == '#':
			output_map[y][x] = '#'


for y in range(height):
	print( ''.join(map(str,output_map[y])))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            S[i][j] = 0
            for k in range(-1, 2):
                for l in range(-1, 2):
                    if k != 0 or l != 0:
                        if 0 < i+k < H-1 and 0 < j+l < W-1 and S[i+k][j+l] == "#":
                            S[i][j] += 1

            S[i][j] = str(S[i][j])

    print("".join(S[i]))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = [input() for i in range(H)]
C = [[0 for i in range(W)] for j in range(H)]
 
dx = [1, 1, 0, -1, -1, -1, 0, 1]
dy = [0, 1, 1, 1, 0, -1, -1, -1]
 
for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      for k in range(8):
        if 0 <= j + dx[k] < W and 0 <= i + dy[k] < H:
          if S[i + dy[k]][j + dx[k]] == '#':
            C[i][j] += 1
          else:
            pass
        else:
          pass
    else:
      C[i][j] = '#'
 
for i in range(H):
  for j in range(W):
    print(C[i][j], end = '')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = [input() for i in range(H)]
C = [[0 for i in range(W)] for j in range(H)]
 
dx = [1, 1, 0, -1, -1, -1, 0, 1]
dy = [0, 1, 1, 1, 0, -1, -1, -1]
 
for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      for k in range(8):
        if 0 <= j + dx[k] < W and 0 <= i + dy[k] < H:
          if S[i + dy[k]][j + dx[k]] == '#':
            C[i][j] += 1
    else:
      C[i][j] = '#'
 
for i in range(H):
  for j in range(W):
    print(C[i][j], end = '')

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
mine = []
for i in range(h):
    mine.append([])
    inp = input()
    for j in range(w):
        mine[i].append(inp[j])
for i in range(h):
    for j in range(w):
        if mine[i][j] == '.':
            cnt = 0
            for k in range(3):
                for l in range(3):
                    try:
                        if mine[i-1+k][j+l-1] == '#':
                            cnt+= 1
                    except:
                        continue
            mine[i][j] = str(cnt)
    print(''.join(mine[i]))

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
mine = []
for i in range(h):
    mine.append([])
    inp = input()
    for j in range(w):
        mine[i].append(inp[j])
for i in range(h):
    for j in range(w):
        if mine[i][j] == '.':
            cnt = 0
            for k in range(3):
                for l in range(3):
                    try:
                        if mine[i-1+k][j+l-1] == '#':
                            cnt+= 1
                    except:
                        continue
            mine[i][j] = str(cnt)
print(mine)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
mine = []
for i in range(h):
    mine.append([])
    inp = input()
    for j in range(w):
        mine[i].append(inp[j])
print(mine)
for i in range(h):
    for j in range(w):
        if mine[i][j] == '.':
            cnt = 0
            for k in range(3):
                for l in range(3):
                    try:
                        if mine[i-1+k][j+l-1] == '#':
                            cnt+= 1
                    except:
                        continue
            mine[i][j] = str(cnt)
print(mine)

Submission status: Wrong Answer

Solution code:
h,w = map(int, input().split())
s = []
s.append((". " * (w + 2)).split())
for i in range(h):
    b = "." + input() + "."
    s.append(list(b))
s.append((". " * (w + 2)).split())
for i in range(1,h + 1):
    for f in range(1, w + 1):
        if s[i][f] == "#":
            for x in range(-1, 2, 1):
                for y in range(-1, 2, 1):
                    if s[i+x][f+y] == ".":
                        s[i+x][f+y] = 1
                    elif isinstance(s[i+x][f+y], int):
                        s[i+x][f+y] += 1
for i in range(1, h + 1):
    print("".join(map(str, s[i][1:w+1])))

Submission status: Wrong Answer

Solution code:
H,W = map(int, input().split())
print(H,W)
S = [input() for i in range(H)]

count = []
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            cnt = 0
            for x in [-1, 0, 1]:
                for y in [-1, 0, 1]:
                    if 0 <= i+x < H and 0 <= j+y < W:
                        if S[i+x][j+y] == "#":
                            cnt += 1
            print(cnt,end="")
        else:
            print("#",end="")
    print()

Submission status: Wrong Answer

Solution code:
H,W = map(int, input().split())
S = []

for _ in range(H):
  S.append([s for s in input()])

for h in range(H):
  for w in range(W):
    if S[h][w] == ".":
      a = 0
      for x in [-1, 0, 1]:
        for y in [-1, 0, 1]:
          if 0 <= h+x < H and 0 <= w+y < W:
            if S[h+x][w+y] == "#":
              a += 1
      S[h][w] = str(a)

print(S)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
dx=[1,1,1,0,0,-1,-1,-1]
dy=[-1,0,1,1,-1,-1,0,1]
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            cnt=0
            for k in range(8):
                x=i+dx[k]
                y=j+dy[k]
                if x>=0 and x<h and y>=0 and y<w and s[x][y]=="#":
                    cnt+=1
            print(cnt)
            s[i][j]=str(cnt)
for i in s:
    print ("".join(i))

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
dx=[1,1,1,0,0,-1,-1,-1]
dy=[-1,0,1,1,-1,-1,0,1]
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            cnt=0
            for k in range(8):
                x=i+dx[k]
                y=j+dy[k]
                if x>=0 and y>=0 and s[i][j]=="#":
                    cnt+=1
            s[i][j]=str(cnt)
for i in s:
    print ("".join(i))

Submission status: Wrong Answer

Solution code:
hw = input()
hw = hw.split()
h = int(hw[0])  #hは行, 1 <= h
w = int(hw[1])  #wは列, w <= 50

board_input = []
board_output = []

for i in range(h):
    b = input()
    board_input.append(b)

dx = [1, 0, -1, 0, 1, -1, -1, 1]
dy = [0, 1, 0, -1, 1, 1, -1, -1]

for i in range(h):
    s = ""
    for j in range(w):
        if board_input[i][j] == '#':
            s += '#'
            continue

        num = 0
        for d in range(8):
            ni = i + dx[d]
            nj = j + dy[d]
            if h - 1 < ni or w - 1 < nj:
                continue
            if board_input[ni][nj] == '#':
                num += 1
                
        s += str(num)
    board_output.append(s)


for i in range(h):
    print(board_output[i])

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = []
for h in range(H):
  S.append(list(input()))


for h in range(H):
    for w in range(W):
        cnt = 0
        if S[h][w]==".":
            if w > 0:
                cnt += int(S[h][w-1] == "#")
            if w < W-1:
                cnt += int(S[h][w+1] == "#")
                
            if h > 0:
                cnt += int(S[h-1][w] == "#")
                if w > 0:
                    cnt += int(S[h-1][w-1] == "#")
                if w < W-1:
                    cnt += int(S[h-1][w+1] == "#")
                    
            if h < H-1:
                cnt += int(S[h+1][w] == "#")
                if w > 0:
                    cnt += int(S[h+1][w-1] == "#")
                if w < W-1:
                    cnt += int(S[h+1][w+1] == "#")
            
            S[h][w] = cnt

print(S)

Submission status: Wrong Answer

Solution code:
import numpy as np
h,w=map(int, input().split())
a=[list(input()) for i in range(h)]
a=np.array(a)
for i in range(h):
    for j in range(w):
        if a[i][j]=='.':
            b=a[max(i-1,0):min(i+2,w),max(j-1,0):min(j+2,w)].flatten()
            a[i][j]=sum(b=='#')
for i in a:
    print(''.join(i))

Submission status: Wrong Answer

Solution code:
import numpy as np
h,w=map(int, input().split())
a=[list(input()) for i in range(h)]
a=np.array(a)
c=np.ones((3,3))
for i in range(h):
    for j in range(w):
        if a[i][j]=='.':
            a[i][j]=c[a[max(i-1,0):min(i+2,w),max(j-1,0):min(j+2,w)]=='#'].sum()
for i in a:
    print(''.join(i))

Submission status: Wrong Answer

Solution code:
import numpy as np
h,w=map(int, input().split())
a=[list(input()) for i in range(h)]
a=np.array(a)
for i in range(h):
    for j in range(w):
        if a[i][j]=='.':
            a[i][j]=a[a[max(i-1,0):min(i+2,w),max(j-1,0):min(j+2,w)]=='#'].size
for i in a:
    print(''.join(i))

Submission status: Wrong Answer

Solution code:
import numpy as np
h,w=map(int, input().split())
a=[list(input()) for i in range(h)]
a=np.array(a)
for i in range(h):
    for j in range(w):
        if a[i][j]=='.':
            a[i][j]=a[a[max(i-1,0):min(i+2,w-1),max(j-1,0):min(j+2,w-1)]=='#'].size
for i in a:
    print(''.join(i))

Submission status: Wrong Answer

Solution code:
import numpy as np
h,w=map(int, input().split())
a=[list(input()) for i in range(h)]
a=np.array(a)
for i in range(h):
    for j in range(w):
        if a[i][j]=='.':
            print(a[max(i-1,0):min(i+2,w-1),max(j-1,0):min(j+2,w-1)])
            a[i][j]=a[a[max(i-1,0):min(i+2,w-2),max(j-1,0):min(j+2,w-2)]=='#'].size
for i in a:
    print(''.join(i))

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
a=[]
for i in range(h):
    a.append(input())
dx=[1,0,-1,0,1,-1,-1,1]
dy=[0,1,0,-1,1,1,-1,-1]
b=[[""] * w] * h
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            continue
        num=0
        for d in range(8):
            ni=i+dx[d]
            nj=j+dy[d]
            if ni<0 or h<=ni:
                continue
            if nj<0 or w<=nj:
                continue
            if a[ni][nj]=='#':
                num+=1
        b[i][j]=str(num)
for i in range(h):
    for j in range(w):
        print(b[i][j],end='')
    print()

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
for i in range(h):
    ans = []
    for j in range(w):
        bomb = 0
        if s[i][j] == ".":
            for k in [0, -1, 1]:
                for n in [0, -1, 1]:
                    if i + k < h and j + n < w:
                        if s[i + k][j + n] == "#":
                            bomb += 1
            ans.append(str(bomb))
        else:
            ans.append("#")
    print("".join(ans))

Submission status: Wrong Answer

Solution code:
H,W = (int(i) for i in input().split())

S = ["."*W]


for i in range(H):
    S.append("." + input() + ".")

S.append("."*W)

#全部０の一回り大きい配列を作っておく
tmpans = [0]*(W+2)
ans = []
for i in range(H+2):
    ans.append(tmpans)


#周りに＋１をしながら進んでいく
for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j] == "#":
            ans[i][j] = -10000
            ans[i-1][j] += 1
            ans[i-1][j-1] += 1
            ans[i-1][j+1] += 1
            ans[i][j-1] += 1
            ans[i][j+1] += 1
            ans[i+1][j] += 1
            ans[i+1][j-1] += 1
            ans[i+1][j+1] += 1

print(ans)