Problem p03574 (python)

Fixed submission:
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(list(input()))
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] == '#':
      continue
    cnt = 0
    for n in range(8):
      ni = i + dx[n]
      nj = j + dy[n]
      if ni < 0 or H <= ni or nj < 0 or W <= nj:
        continue
      if S[ni][nj] == '#':
        cnt += 1
    S[i][j] = str(cnt)


    
for i in range(H):
    print("".join(S[i]))

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(list(input()))
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] == '#':
      continue
    cnt = 0
    for n in range(8):
      ni = i + dx[n]
      nj = j + dy[n]
      if ni < 0 or H <= ni or nj < 0 or W <= nj:
        continue
      if S[ni][nj] == '#':
        cnt += 1
    S[i][j] = str(cnt)


    
for i in range(H):
    print("".join(S[i]))

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(list(input()))
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] == '#':
      continue
    cnt = 0
    for n in range(8):
      ni = i + dx[n]
      nj = j + dy[n]
      if ni < 0 or H <= ni or nj < 0 or W <= nj:
        continue
      if s[ni][nj] == '#':
        cnt += 1
    S[i][j] = str(cnt)


    
for i in range(H):
    print("".join(S[i]))

Buggy submission (verdict: Runtime Error):
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] == '#':
      continue
    cnt = 0
    for n in range(8):
      ni = i + dx[n]
      nj = j + dy[n]
      if ni < 0 or H <= ni or nj < 0 or W <= nj:
        continue
      if s[ni][nj] == '#':
        cnt += 1
    S[i][j] = str(cnt)


    
for i in range(H):
    print("".join(S[i]))

Buggy submission (verdict: Runtime Error):
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 n in range(8):
        ni = i + dx[n]
        nj = j + dy[n]
        if ni < 0 or H <= ni or nj < 0 or W <= nj:
          continue
        if s[ni][nj] == '#':
          cnt += 1
      S[i][j] = str(cnt)

print(S)

Buggy submission (verdict: Runtime Error):
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 n in range(8):
        ni = i + dx[n]
        nj = j + dy[n]
        if ni < 0 or ni >= H:
          continue
        if nj < 0 or nj >= W:
          continue
        if s[ni][nj] == '#':
          cnt += 1
      S[i][j] = str(cnt)

print(S)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = [list(map(int, input().split())) 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 n in range(8):
        ni = i + dx[n]
        nj = j + dy[n]
        if ni < 0 or ni >= H:
          continue
        if nj < 0 or nj >= W:
          continue
        if s[ni][nj] == '#':
          cnt += 1
      S[i][j] = str(cnt)

print(S)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = [list(map(int, input().split())) 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 n in range(8):
        ni = i + dx[n]
        nj = j + dy[n]
        if ni < 0 or ni >= H:
          continue
        if nj < 0 or nj >= W:
          continue
        if s[ni][nj] == '#':
          cnt += 1
      S[i][j] = cnt

print(S)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = [list(map(int, input().split())) 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 n in range(8):
        ni = i + dx
        nj = j + dy
        if ni < 0 or ni >= H:
          continue
        if nj < 0 or nj >= W:
          continue
        if s[ni][nj] == '#':
          cnt += 1
      S[i][j] = cnt

print(S)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = [list(map(int, input().split())) for i in range(H)]

for i in range(H):
  for j in range(W):
    if s[i][j] == '.':
      cnt = 0
      if S[i-1][j-1] == '#':
        cnt += 1
      if S[i-1][j] == '#':
        cnt += 1
      if S[i-1][j+1] == '#':
        cnt += 1
      if S[i][j-1] == '#':
        cnt += 1
      if S[i][j+1] == '#':
        cnt += 1
      if S[i+1][j-1] == '#':
        cnt += 1
      if S[i+1][j] == '#':
        cnt += 1
      if S[i+1][j+1] == '#':
        cnt += 1
      S[i][j] = cnt
    
    
print(S)