Problem p03574 (python)

Fixed submission:
import numpy as np

# 読み込み
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(list(map(str, input().rstrip())))

# 外枠を「.」で囲う準備
li = []
for i in range(H+2):
    li.append(["."]*(W+2))

# 外枠付きSの生成
for i in range(1, H+1):
    li[i][1:-1] = S[i-1]

# カウント用配列の準備
ans = []
for i in range(H+2):
    ans.append([0]*(W+2))
ans = np.array(ans)

# カウント処理
for h in range(1, H+1):
    for w in range(1, W+1):
        if li[h][w]=="#":
            ans[h-1:h+2, w-1:w+2] += 1

# カウント結果から必要な場所だけ切り出す
ans = ans.astype("str")
ans = ans[1:-1, 1:-1]

# 「#」で上書きしながら出力
for h in range(H):
    for w in range(W):
        if S[h][w]=="#":
            ans[h, w] = "#"
    print("".join(ans[h]))

Buggy submission (verdict: Runtime Error):
# 読み込み
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(list(map(str, input().rstrip())))

# 外枠を「.」で囲う準備
li = []
for i in range(H+2):
    li.append(["."]*(W+2))

# 外枠付きSの生成
for i in range(1, H+1):
    li[i][1:-1] = S[i-1]

# カウント用配列の準備
ans = []
for i in range(H+2):
    ans.append([0]*(W+2))
ans = np.array(ans)

# カウント処理
for h in range(1, H+1):
    for w in range(1, W+1):
        if li[h][w]=="#":
            ans[h-1:h+2, w-1:w+2] += 1

# カウント結果から必要な場所だけ切り出す
ans = ans.astype("str")
ans = ans[1:-1, 1:-1]

# 「#」で上書きしながら出力
for h in range(H):
    for w in range(W):
        if S[h][w]=="#":
            ans[h, w] = "#"
    print("".join(ans[h]))

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())

li = []
for i in range(H+2):
    li.append(["."]*(W+2))

for h in range(H):
    for w in range(W):
        li[h+1][w+1] = input()

S = [i[1:-1] for i in li][1:-1]

import numpy as np
ans = np.zeros([H+2, W+2], dtype=int)

for h in range(1, H):
    for w in range(1, W):
        if li[h][w]=="#":
            ans[h-1:h+2, w-1:w+2] += 1      

ans = ans.astype("str")
ans = ans[1:-1, 1:-1]

for h in range(H):
    for w in range(W):
        if S[h][w]=="#":
            ans[h, w] = "#"

for i in ans:
    print("".join(i))

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())

li = []
for i in range(H+2):
    li.append(["."]*(W+2))

for h in range(H):
    for w in range(W):
        li[h+1][w+1] = input()

S = [i[1:-1] for i in li][1:-1]

import numpy as np
ans = np.zeros([H+2, W+2], dtype=int)

for h in range(1, H+1):
    for w in range(1, W+1):
        if li[h][w]=="#":
            ans[h-1:h+2, w-1:w+2] += 1      

ans = ans.astype("str")
ans = ans[1:-1, 1:-1]

for h in range(H):
    for w in range(W):
        if S[h][w]=="#":
            ans[h, w] = "#"

for i in ans:
    print("".join(i))

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())

li = []
for i in range(H+2):
    li.append(["."]*(W+2))

for h in range(H):
    for w in range(W):
        li[h+1][w+1] = input()

S = [i[1:-1] for i in li][1:-1]

import numpy as np
ans = np.zeros([H+2, W+2], dtype=int)

for h in range(1, H+1):
    for w in range(1, W+1):
        if li[h][w]=="#":
            ans[h-1:h+2, w-1:w+2] += 1      

ans = ans.astype("str")
ans = ans[1:-1, 1:-1]

for h in range(H):
    for w in range(W):
        if S[h][w]=="#":
            ans[h, w] = "#"

for i in ans:
    print("".join(i))