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 = map(int, input().split())
L = []
for i in range(H):
    S = list(input())
    L.append(S)

for i in range(H):
    for j in range(len(L[i])):
        if L[i][j] == '.':
            cnt = 0
            for k in range(-1, 2):
                for l in range(-1, 2):
                    if ((i+k) < H) and ((j+l) < len(L[i])) and ((j+l) >= 0):
                        if L[i+k][j+l] == '#':
                            cnt += 1
            L[i][j] = str(cnt)

for i in range(len(L)):
    print(''.join(L[i]))

Submission status: Wrong Answer

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

for i in range(H):
    for j in range(len(L[i])):
        if L[i][j] == '.':
            cnt = 0
            for k in range(-1, 2):
                for l in range(-1, 2):
                    if (i+k) < H and (j+l) < len(L[i]):
                        if L[i+k][j+l] == '#':
                            cnt += 1
            L[i][j] = str(cnt)

for i in range(len(L)):
    print(''.join(L[i]))

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
a=[list(input()) for i in range(h)]
b=a
for i in range(h):
  for j in range(w):
    if a[i][j]!="#":
      b[i][j]=a[i][max(0,j-1):min(w-1,j+2)].count("#")
      if i!=0:
        b[i][j]+=a[i-1][max(0,j-1):min(w-1,j+2)].count("#")
      if i!=h-1:
        b[i][j]+=a[i+1][max(0,j-1):min(w-1,j+2)].count("#")
for i in range(h):
  print("".join(str(j) for j in b[i]))

Submission status: Wrong Answer

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

for i in range(h):
    s = input()
    sl.append(s)

def scheck(s):
    if s == "#":
        return 1
    else:
        return 0
        
def check(i,j,sl):
    cnt = 0
    for k in range(-1,2):
        for l in range(-1,2):
            if h > i+k >= 0 and w > j+l >= 0:
                cnt += scheck(sl[i+k][j+l])
    return str(cnt)

for i in range(h):
    for j in range(w):
        if sl[i][j] == ".":
            bl[i][j] = check(i,j,sl)
        else:
            bl[i][j] = "#"

for b in bl:
    print(*b)

Submission status: Wrong Answer

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

for i in range(h):
    s = input()
    sl.append(s)

def scheck(s):
    if s == "#":
        return 1
    else:
        return 0
        
def check(i,j,sl):
    cnt = 0
    for k in range(-1,2):
        for l in range(-1,2):
            if h > i+k >= 0 and w > j+l >= 0:
                cnt += scheck(sl[i+k][j+l])
    return cnt

for i in range(h):
    for j in range(w):
        if sl[i][j] == ".":
            bl[i][j] = check(i,j,sl)
        else:
            bl[i][j] = "#"

for b in bl:
    print(*b)

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] == ".":
            c = 0
            for x in range(-1, 2):
                for y in range(-1, 2):
                    if x == 0 and y == 0:
                        break
                    else:
                        if 0 <= i+y and 0 <= j+x and i+y < h and j+x < w:
                            if s[i+y][j+x] == "#":
                                c += 1
            s[i][j] = str(c)
for a in range(h):
    print("".join(s[a]))

Submission status: Wrong Answer

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

di=[1,1,0,-1,-1,-1,0,1]
dj=[0,1,1,1,0,-1,-1,-1]

for i in range(H):
    for j in range(W):
        ans=0
        if S[i][j]=='#':
            continue
        for k in range(8):
            ni=i+di[k]
            nj=j+dj[k]
            if ni<0 or nj<0 or ni>=H or nj>=W:
                continue
            if S[ni][nj]=='#':
                ans+=1
            S[i][j]=str(ans)
for i in range(H):
    for j in range(W):
        print(S[i][j],end='')
    print()

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(map(str, input())) for i in range(h)]
print(s)
ans = s

di = [1, 0, -1, 0, 1, -1, -1, 1]
dj = [0, 1, 0, -1, 1, 1, -1, -1]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            continue
        cnt = 0
        for d in range(8):
            if i + di[d] <0 or i + di[d] > h - 1 or j + dj[d] < 0 or j + dj[d] > w - 1:
                continue
            if s[i + di[d]][j +dj[d]] == '#':
                cnt += 1
        ans[i][j] = cnt

for i in range(h):
    print(''.join(map(str, ans[i])))

Submission status: Wrong Answer

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

S = [list(input()) for i in range(H)]

if H >= 3 and W >= 3:
  for i in range(1,H-1):
    for j in range(1,W-1):
      if S[i][j] == '.':
        x = [S[i-1][j-1], S[i-1][j], S[i-1][j+1], S[i][j-1], S[i][j+1],S[i+1][j-1], S[i+1][j],S[i+1][j+1]]
        S[i][j] = x.count('#')
if W >=3 and H >=2:
  for j in range(1,W-1):
    if S[0][j] == '.':
      x = [S[0][j-1], S[0][j+1], S[1][j-1], S[1][j], S[1][j+1]]
      S[0][j] = x.count('#')

    if S[H-1][j] == '.':
      x = [S[H-1][j-1], S[H-1][j+1], S[H-2][j-1], S[H-2][j], S[H-2][j+1]]
      S[H-1][j] = x.count('#')
      
if H >=3 and W >=2:
  for i in range(1, H-1):
    if S[i][0] == '.':
      x =[S[i-1][0],S[i-1][1],  S[i][1], S[i+1][0], S[i+1][1]]
      S[i][0] = x.count('#')
    if S[i][W-1] == '.':
      x =[S[i-1][W-1],S[i-1][W-2],  S[i][W-2], S[i+1][W-1], S[i+1][W-2]]
      S[i][W-1] = x.count('#')
if H >=2 and W >= 2:
  if S[0][0] == '.':
    x = [S[0][1], S[1][0], S[1][1]]
    S[0][0] =x.count('#')
  if S[0][W-1] == '.':
    x = [S[0][W-2], S[1][W-1], S[1][W-2]]
    S[0][W-1] = x.count('#')
  if S[H-1][0] == '.':
    x = [S[H-1][1], S[H-2][0], S[H-2][1]]
    S[H-1][0] = x.count('#')

  if S[H-1][W-1] == '.':
    x = [S[H-1][W-2], S[H-2][W-1], S[H-2][W-2]]
    S[H-1][W-1] = x.count('#')
    
if H == 1 and W >=2:
  if S[0][0] == '.':
    x = [S[0][1]]
    S[0][0] = x.count('#')
  if S[0][W-1] == '.':
    x = [S[0][W-2]]
    S[0][W-1] = x.count('#')
if H >= 2 and W ==1:
  if S[0][0] == '.':
    x =[S[1][0]]
    S[0][0] = s.count('#')
  if S[H-1][0] == '.':
    x = [S[H-2][0]]
    S[H-1][0] = x.count('#')
    
if H == 1 and W == 1:
  if S[0][0] == '.':
    S[0][0] = 0

for i in range(len(S)):
  S[i] = [str(x) for x in S[i]]
  print(''.join(S[i]))

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())

l=[list(input()) for i in range(h)]
ans=[[0]*w for i in range(h)]

for i in range(h):
  for j in range(w):
    if l[i][j]=="#":
      ans[i][j]=="#"
    else:
      for a in range(-1,2):
        for b in range(-1,2):
          if 0<=i+a<h and 0<=j+b<w and l[i+a][j+b]=="#":
            ans[i][j]+=1
            
for i in range(h):
  print(*ans[i])

Submission status: Wrong Answer

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

if (h == 1)&(w==1):
	if s[0][0] == "#":
		print(s)
	else:
		print(0)

elif (h == 1)&(w!=1):
    for j in range(w):
        if j == 0:
            s[0][j] = s[0][j].replace(".",str(s[0][j+1].count("#")))
        elif j == w-1:
            s[0][j] = s[0][j].replace(".",str(s[0][j-1].count("#")))
        else:
            s[0][j] = s[0][j].replace(".",str([s[0][j-1],s[0][j+1]].count("#")))

elif (h != 1)&(w==1):
    for i in range(h):
        if i == 0:
            s[i][0] = s[i][0].replace(".",str(s[i+1][0].count("#")))
        elif i == h-1:
            s[i][0] = s[i][0].replace(".",str(s[i-1][0].count("#")))
        else:
            s[i][0] = s[i][0].replace(".",str([s[i-1][0],s[i+1][0]].count("#")))
else:
    for i in range(len(s)):
        if i == 0:
            for j in range(w):
                if j == 0:
                    s[i][j] = s[i][j].replace(".",str([s[i][j+1],s[i+1][j],s[i+1][j+1]].count("#")))
                elif j == w-1:
                    s[i][j] = s[i][j].replace(".",str([s[i][j-1],s[i+1][j],s[i+1][j-1]].count("#")))
                else:
                    s[i][j] = s[i][j].replace(".",str([s[i][j-1],s[i][j+1],s[i+1][j],s[i+1][j+1],s[i+1][j-1]].count("#")))
        elif i == h-1:
            for j in range(w):
                if j == 0:
                    s[i][j] = s[i][j].replace(".",str([s[i][j+1],s[i-1][j],s[i-1][j+1]].count("#")))
                elif j == w-1:
                    s[i][j] = s[i][j].replace(".",str([s[i][j-1],s[i-1][j],s[i-1][j-1]].count("#")))
                else:
                    s[i][j] = s[i][j].replace(".",str([s[i][j-1],s[i][j+1],s[i-1][j],s[i-1][j+1],s[i-1][j-1]].count("#")))
        else:
            for j in range(w):
                if j == 0:
                    s[i][j] = s[i][j].replace(".",str([s[i][j+1],s[i-1][j],s[i-1][j+1],s[i+1][j],s[i+1][j+1]].count("#")))
                elif j == w-1:
                    s[i][j] = s[i][j].replace(".",str([s[i][j-1],s[i-1][j],s[i-1][j-1],s[i+1][j],s[i+1][j-1]].count("#")))
                else:
                    s[i][j] = s[i][j].replace(".",str([s[i][j-1],s[i][j+1],s[i-1][j],s[i-1][j+1],s[i-1][j-1],s[i+1][j],s[i+1][j+1],s[i+1][j-1]].count("#")))

for k in s:
    print("".join(k))

Submission status: Wrong Answer

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

if (h == 1)&(w==1):
    print(s)

elif (h == 1)&(w!=1):
    for j in range(w):
        if j == 0:
            s[0][j] = s[0][j].replace(".",str(s[0][j+1].count("#")))
        elif j == w-1:
            s[0][j] = s[0][j].replace(".",str(s[0][j-1].count("#")))
        else:
            s[0][j] = s[0][j].replace(".",str([s[0][j-1],s[0][j+1]].count("#")))

elif (h != 1)&(w==1):
    for i in range(h):
        if i == 0:
            s[i][0] = s[i][0].replace(".",str(s[i+1][0].count("#")))
        elif i == h-1:
            s[i][0] = s[i][0].replace(".",str(s[i-1][0].count("#")))
        else:
            s[i][0] = s[i][0].replace(".",str([s[i-1][0],s[i+1][0]].count("#")))
else:
    for i in range(len(s)):
        if i == 0:
            for j in range(w):
                if j == 0:
                    s[i][j] = s[i][j].replace(".",str([s[i][j+1],s[i+1][j],s[i+1][j+1]].count("#")))
                elif j == w-1:
                    s[i][j] = s[i][j].replace(".",str([s[i][j-1],s[i+1][j],s[i+1][j-1]].count("#")))
                else:
                    s[i][j] = s[i][j].replace(".",str([s[i][j-1],s[i][j+1],s[i+1][j],s[i+1][j+1],s[i+1][j-1]].count("#")))
        elif i == h-1:
            for j in range(w):
                if j == 0:
                    s[i][j] = s[i][j].replace(".",str([s[i][j+1],s[i-1][j],s[i-1][j+1]].count("#")))
                elif j == w-1:
                    s[i][j] = s[i][j].replace(".",str([s[i][j-1],s[i-1][j],s[i-1][j-1]].count("#")))
                else:
                    s[i][j] = s[i][j].replace(".",str([s[i][j-1],s[i][j+1],s[i-1][j],s[i-1][j+1],s[i-1][j-1]].count("#")))
        else:
            for j in range(w):
                if j == 0:
                    s[i][j] = s[i][j].replace(".",str([s[i][j+1],s[i-1][j],s[i-1][j+1],s[i+1][j],s[i+1][j+1]].count("#")))
                elif j == w-1:
                    s[i][j] = s[i][j].replace(".",str([s[i][j-1],s[i-1][j],s[i-1][j-1],s[i+1][j],s[i+1][j-1]].count("#")))
                else:
                    s[i][j] = s[i][j].replace(".",str([s[i][j-1],s[i][j+1],s[i-1][j],s[i-1][j+1],s[i-1][j-1],s[i+1][j],s[i+1][j+1],s[i+1][j-1]].count("#")))

for k in s:
    print("".join(k))

Submission status: Wrong Answer

Solution code:
def mine_count(x, y, ans):
    ans[y][x] = 0
    for nx, ny in (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1):
        if y+ny < len(ans) and x+nx < len(ans[0]):
            if ans[y+ny][x+nx] == "#":
                ans[y][x] += 1
            else:
                pass
    return ans


H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
ans = S
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            ans = mine_count(j, i, ans)

for row in ans:
    for item in row:
        print(item, end="")
    print()

Submission status: Wrong Answer

Solution code:
dx = [1, 0, -1, 0, 1, -1, -1, 1]
dy = [0, 1, 0, -1, 1, 1, -1, -1]

# 入力
H, W = map(int, input().split())
S = [input() for _ in range(H)]

# 各マス (i, j) について順に処理
for i in range(H):
    for j in range(W):
        if S[i][j] != '.':
            continue
        S[i] = S[i].replace('.', '0', 1)
        counter = 0
        for d in range(8):
            ni = i + dx[d]
            nj = j + dy[d]
            if ni < 0 or ni >= H or nj < 0 or nj >= W:
                continue
            if S[ni][nj] == '#':
                counter += 1
        S[i] = S[i].replace('0', str(counter))

for row in S:
    print(row)

Submission status: Wrong Answer

Solution code:
h, w = (int(x) for x in input().split())
s = []
ans = []
rev = ""
for row in range(1, h+1):
    for col, t in enumerate(input()):
        s.append([(row,col+1),t])

for index, factor in enumerate(s):
    count =0
    if factor[1] != "#":
        if (index+1)%w == 1:
            for point in [index +1,index -w+1, index -w, index +w, index +w+1]:
                if 0 <= point and point < len(s) and s[point][1] == "#":
                    count += 1
        elif (index+1)%w == 0:
            for point in [index -1,index -w, index -w-1, index +w-1, index +w]:
                if 0 <= point and point < len(s) and s[point][1] == "#":
                    count += 1
        else:
            for point in [index -1, index +1,index -w+1, index -w, index -w-1, index +w-1, index +w, index +w+1]:
                if 0 <= point and point < len(s) and s[point][1] == "#":
                    count += 1
        ans.append(count)
    else:
        ans.append("#")

while(ans != []):
    for num in range(w):
        rev += str(ans[0])
        del ans[0]
    rev += "\n"

print(rev)

Submission status: Wrong Answer

Solution code:
h, w = (int(x) for x in input().split())
s = []
ans = []
rev = ""
for row in range(1, h+1):
    for col, t in enumerate(input()):
        s.append([(row,col+1),t])

for index, factor in enumerate(s):
    count =0
    if factor[1] != "#":
        if (index+1)%w == 1:
            for point in [index +1,index -w+1, index -w, index +w, index +w+1]:
                if 0 <= point and point < len(s) and s[point][1] == "#":
                    count += 1
        elif (index+1)%w == 0:
            for point in [index -1,index -w, index -w-1, index +w-1, index +w]:
                if 0 <= point and point < len(s) and s[point][1] == "#":
                    count += 1
        else:
            for point in [index -1, index +1,index -w+1, index -w, index -w-1, index +w-1, index +w, index +w+1]:
                if 0 <= point and point < len(s) and s[point][1] == "#":
                    print(s[point])
                    count += 1
        ans.append(count)
    else:
        ans.append("#")

while(ans != []):
    for num in range(w):
        rev += str(ans[0])
        del ans[0]
    rev += "\n"

print(rev)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

dh = [0,1,0,-1,1,-1,1,-1]
dw = [1,0,-1,0,1,-1,-1,1]

for h in range(H):
    for w in range(W):
        #マス(h,w)について
        if S[h][w] == '#':
            continue
        else:
            cnt= 0
            for v in range(8):
                nxt_h = h + dh[v]
                nxt_w = w + dw[v]
                if not(-1<nxt_h<H) or not(-1<nxt_w<W):
                    continue
                elif S[nxt_h][nxt_w] == '#':
                    cnt += 1
                S[h][w] = 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 _ in range(H)]

dh = [0,1,0,-1,1,-1,1,-1]
dw = [1,0,-1,0,1,-1,-1,1]

for h in range(H):
    for w in range(W):
        #マス(h,w)について
        if S[h][w] == '#':
            continue
        else:
            cnt= 0
            for v in range(8):
                nxt_h = h + dh[v]
                nxt_w = w + dw[v]
                if not(-1<nxt_h<H) or not(-1<nxt_w<W):
                    continue
                if S[nxt_h][nxt_w] == '#':
                    cnt += 1
                S[h][w] = str(cnt)
for i in S:
    print(''.join(i))

Submission status: Wrong Answer

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

dh = [0,1,0,-1,1,-1,1,-1]
dw = [1,0,-1,0,1,-1,-1,1]

for h in range(H):
    for w in range(W):
        #マス(h,w)について
        if S[h][w] == '#':
            continue
        else:
            cnt= 0
            for v in range(8):
                nxt_h = h + dh[v]
                nxt_w = w + dw[v]
                if not(-1<nxt_h<H) or not(-1<nxt_w<W):
                    continue
                if S[nxt_h][nxt_w] == '#':
                    cnt += 1
                S[h][w] = str(cnt)
for i in S:
    print(''.join(i))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


H, W = zz()
table = []
for i in range(H):
    table.append(input())
ans_table = [[0]*W 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):
        tmp = 0
        if (table[i][j] == '.'):
            for x, y in zip(dx, dy):
                if (i + x >= H or j+y >= W):
                    continue
                if (table[i + x][j + y] == '#'):
                    tmp += 1
            ans_table[i][j] = tmp
        else:
            ans_table[i][j] = '#'


for _table in ans_table:
    print(*_table, sep='')

Submission status: Wrong Answer

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

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

for i in range(0, h):
    for j in range(0, w):
        if s[i][j] != '.':
            continue

        cnt = 0
        for k in range(0, 8):
            ni = i + dy[k]
            nj = j + dx[k]

            if not (ni < 0 or h <= ni) and not (nj < 0 or w <= nj) and s[ni][nj] == '#':
                cnt += 1

        s[i][j] = str(cnt)

[print(''.join(s[ii])) for ii in range(0, h)]

Submission status: Wrong Answer

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

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

for i in range(0, h):
    for j in range(0, w):
        if s[i][j] != '.':
            continue

        cnt = 0
        for k in range(0, 8):
            ni = i + dy[k]
            nj = j + dx[k]

            if not (ni < 0 or h <= ni) and not (nj < 0 or w <= nj) and s[ni][nj] == '#':
                cnt += 1

        s[i][j] = str(cnt)

[print(s[ii]) for ii in range(0, h)]

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
S=[]
for i in range(H):
  t=input()
  s=[]
  for j in t:
    if j==".":
      s.append(0)
    else:
      s.append(j)
  S.append(s)
for k in range(H):
  for l in range(W):
    if S[k][l]=="#":
      try:
        S[k-1][l-1]+=1
      except:
        pass
      try:
        S[k-1][l]+=1
      except:
        pass
      try:
        S[k-1][l+1]+=1
      except:
        pass
      try:
        S[k][l-1]+=1
      except:
        pass
      try:
        S[k][l+1]+=1
      except:
        pass
      try:
        S[k+1][l-1]+=1
      except:
        pass
      try:
        S[k+1][l]+=1
      except:
        pass
      try:
        S[k+1][l+1]+=1
      except:
        pass
for m in S:
  ans=""
  for n in m:
    ans+=str(n)
  print(ans)

Submission status: Wrong Answer

Solution code:

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
moves = ((1, 0), (0, 1), (0, -1), (-1, 0), (-1, -1), (-1, 1), (1, -1), (1,1))
c = [[0]*W for _ in range(H)]
for i in range(H):
  for j in range(W):
    cnt = 0
    if S[i][j] == "#":
      c[i][j] = "#"
      continue
    for dy, dx in moves:
      ny = i + dy
      nx = j + dx
      if 0 <= ny < H and 0 <= nx < W and S[ny][nx] == '#':
        cnt += 1
    c[i][j] = cnt

print(c) 
for i in c:
  i = list(map(str, i))
  print("".join(i))

Submission status: Wrong Answer

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    h, w = i_map()
    str_list = s_row_list(h)

    for i in range(h):
        for j in range(w):
            if str_list[i][j] == '#':
                continue
            count = 0
            for dx, dy in ([1, 0], [-1, 0], [0, 1], [0, -1], [1, 1], [1, -1], [-1, 1], [-1, -1]):
                ni = i + dx
                nj = j + dy
                if ni < 0 or ni >= h or nj < 0 or nj >= w:
                    continue
                if str_list[ni][nj] == '#':
                    count += 1
            str_list[i][j] = count

    for i in range(h):
        print(*str_list[i])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(h):
    i = list(input())
    s.append(i)

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 s[i][j] == '#':
            continue

        tmp = 0
        for t in range(8):
            ni = i + dx[t]
            nj = j + dy[t]
            if ni < 0 or h <= ni: continue
            if nj < 0 or w <= nj: continue
            if s[ni][nj] == '#':
                tmp += 1

        s[i][j] = str(tmp)

print(s)

Submission status: Wrong Answer

Solution code:
import numpy as np

H,W= list(map(int,input().split()))
a=np.array([list(input()) for i in range(H)])
b=np.zeros((H,W))

for i in range(H):
    for j in range(W):
        if a[i][j]=="#":
            if i>=1 and j>=1:
                b[i-1][j-1] += 1
            if i>=1:
                b[i-1][j] += 1
            if i>=1 and j<W-1:
                b[i-1][j+1] +=1

            if j>=1:
                b[i][j-1] += 1
            #    b[i][j] += 1
            if j<W-1:
                b[i][j+1] +=1

            if i<H-1 and j>=1:
                b[i+1][j-1] += 1
            if i<H-1:
                b[i+1][j] += 1
            if i<H-1 and j<W-1:
                b[i+1][j+1] +=1

print(b)

Submission status: Wrong Answer

Solution code:
import numpy as np

H,W= list(map(int,input().split()))
a=np.array([list(input()) for i in range(H)])
b=np.zeros((H,W))
print(a[0][0])
print(b)

for i in range(H):
    for j in range(W):
        if a[i][j]=="#":
            if i>=1 and j>=1:
                b[i-1][j-1] += 1
            if i>=1:
                b[i-1][j] += 1
            if i>=1 and j<W-1:
                b[i-1][j+1] +=1

            if j>=1:
                b[i][j-1] += 1
            #    b[i][j] += 1
            if j<W-1:
                b[i][j+1] +=1

            if i<H-1 and j>=1:
                b[i+1][j-1] += 1
            if i<H-1:
                b[i+1][j] += 1
            if i<H-1 and j<W-1:
                b[i+1][j+1] +=1

print(b)

Submission status: Wrong Answer

Solution code:
#6re
h,w = map(int,input().split())
s = []
s.append(list("." for i in range(w+2)))
for i in range(h):
    s.append(list("."+input()+"."))
s.append(list("." for i in range(w+2)))
ans = [[0 for j in range(w) ] for i in range(h) ]
    
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] != "#":
            for m in range(i-1,i+2):
                for n in range(j-1,j+2):
                    if s[m][n] == "#":
                        ans[i-1][j-1] += 1
        else:
            ans[i-1][j-1] = "#"
                
print(ans)

Submission status: Wrong Answer

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

def kazu(h,w):
    houkou = [[1,0],[1,-1],[0,-1],[-1,-1],[-1,0],[-1,1],[0,1],[1,1]]
    count = 0
    for ya in houkou:
        try:
            if masu[h+ya[0]][w+ya[1]] == '#':
                count += 1
        except:pass
    return count

for w in range(W):
    for h in range(H):
        if masu[h][w]=='.':
            masu[h][w] = kazu(h,w)

for l in masu:print(*l,sep='')

Submission status: Wrong Answer

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

def kazu(h,w):
    houkou = [[1,0],[1,-1],[0,-1],[-1,-1],[-1,0],[-1,1],[0,1],[1,1]]
    count = 0
    for ya in houkou:
        try:
            if masu[h+ya[0]][w+ya[1]] == '#':
                count += 1
        except:pass
    return count

for w in range(W):
    for h in range(H):
        if masu[h][w]=='.':
            masu[h][w] = kazu(h,w)

for l in masu:print(*l,sep='')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split(' '))
print("{} {}".format(H, W))
count = [['0']*W for i in range(H)]

def update_count(i, j, count):
    count[i][j] = '#'
    start_i = 0 if i-1 < 0 else i-1
    end_i = H if i + 2 > H else i+2
    start_j = 0 if j-1 < 0 else j-1
    end_j = W if j + 2 > W else j+2
    for k in range(start_i, end_i):
        for l in range(start_j, end_j):
            if count[k][l] != '#':
                count[k][l] = str(1 + int(count[k][l]))
    return count

for i in range(H):
    S = input()
    for j in range(W):
        if S[j] == '#':
            count = update_count(i, j, count)

for i in range(H):
    print(''.join(count[i]))

Submission status: Wrong Answer

Solution code:
from collections import deque
H, W = map(int,input().split())
sl = []
for _ in range(H):
    sl.append(list(input()))



for i in range(H):
    for j in range(W):
        if sl[i][j] == '#':
            continue

        directions = [[1,0],[0,1],[-1,0],[0,-1],[1,1],[-1,-1],[1,-1],[-1,1]]
        cnt = 0
        for d in directions:
            y,x = i+d[0],j+d[1]
            if i+d[0] >= H:
                y = H-1
            if j+d[1] >= W:
                x = W-1
            if sl[y][x] == '#':
               cnt += 1
        sl[i][j] = str(cnt)

for v in sl:
    print(''.join(v))

Submission status: Wrong Answer

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

ans = [[0]*W for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            ans[i][j] += 11

#入力が1列の場合
# if W == 1:
#     for i in range(H-1):
#         if ans[i+1][0] > 10:
#             ans[i][0] += 1
#     for i in range(1, H):
#         if ans[i-1][0] > 10:
#             ans[i][0] += 1

#     for i in range(H):
#         if ans[i][0] > 10:
#             ans[i][0] = "#"
#         ans[i] = map(str, ans[i])
#         ans[i] = "".join(ans[i])

#     for a in ans:
#         print(a)
#     exit()


#横方向の確認
for i in range(H):
    for j in range(W - 1):
        if ans[i][j+1] > 10:
            ans[i][j] += 1
    for j in range(1, W):
        if ans[i][j-1] > 10:
            ans[i][j] += 1

#縦方向の確認
for j in range(1, W-1):
    for i in range(H-1):
        if ans[i+1][j-1] > 10:
            ans[i][j] += 1
        if ans[i+1][j] > 10:
            ans[i][j] += 1
        if ans[i+1][j+1] > 10:
            ans[i][j] += 1

    for i in range(1, H):
        if ans[i-1][j-1] > 10:
            ans[i][j] += 1
        if ans[i-1][j] > 10:
            ans[i][j] += 1
        if ans[i-1][j+1] > 10:
            ans[i][j] += 1

#j = 0
for i in range(H-1):
    if ans[i+1][0] > 10:
        ans[i][0] += 1
    if W > 2 and ans[i+1][1] > 10:
        ans[i][0] += 1
for i in range(1, H):
    if ans[i-1][0] > 10:
        ans[i][0] += 1
    if W > 2 and ans[i-1][1] > 10:
        ans[i][0] += 1

#j = W-1
for i in range(H-1):
    if ans[i+1][W-1] > 10:
        ans[i][W-1] += 1
    if ans[i+1][W-2] > 10:
        ans[i][W-1] += 1
for i in range(1, H):
    if ans[i-1][W-1] > 10:
        ans[i][W-1] += 1
    if ans[i-1][W-2] > 10:
        ans[i][W-1] += 1

for i in range(H):
    for j in range(W):
        if ans[i][j] > 10:
            ans[i][j] = "#"
    ans[i] = map(str, ans[i])
    ans[i] = "".join(ans[i])

for a in ans:
    print(a)