Problem p03053 (python)

Fixed submission:
from collections import deque

def bfs():
    while len(que) != 0:
        p = que.popleft()
        for i in range(4):
            nextX = p[0] + moveR[i]
            nextY = p[1] + moveC[i]
            if 0 <= nextX and nextX < H\
                and 0 <= nextY and nextY < W\
                and s[nextX][nextY] != '#'\
                and s[nextX][nextY] == '.':
                s[nextX][nextY] = s[p[0]][p[1]] + 1
                que.append([nextX, nextY])

H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
moveR = [0, 1, -1, 0]
moveC = [1, 0, 0, -1]

que = deque()
for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            que.append([i, j])
            s[i][j] = 0
bfs()
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, s[i][j])
print(ans)

Buggy submission (verdict: Runtime Error):
import copy
 
H, W = map(int, input().split())
 
def fib(msLst, i, j):
    if i > 0:
        msLst[i - 1][j] = '#'
    if i < W - 1:
        msLst[i + 1][j] = '#'
    if j > 0:
        msLst[i][j - 1] = '#'
    if j < H - 1:
        msLst[i][j + 1] = '#'
 
ansCnt = 0
masLst = [['' for i in range(H)] for j in range(W)]
for i in range(W):
    tmp = input()
    for j in range(len(tmp)):
        masLst[i][j] = tmp[j]
 
loopBoean = True
 
while loopBoean:
    jloop = True
    tmp = 0
    msLst = copy.deepcopy(masLst)
    for i in range(W):
        for j in range(H):
            if masLst[i][j] == '#':
                fib(msLst, i, j)
            if masLst[i][j] == '.':
                if tmp == 0:
                    tmp = 1
            if msLst[i][j] != '#':
                jloop = False
    masLst = msLst
    if tmp == 1:
        ansCnt += tmp
 
    if jloop == True:
        loopBoean = False
 
print(ansCnt)

Buggy submission (verdict: Runtime Error):
import copy

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

def fib(msLst, i, j):
    if i > 0:
        msLst[i - 1][j] = '#'
    if i < W - 1:
        msLst[i + 1][j] = '#'
    if j > 0:
        msLst[i][j - 1] = '#'
    if j < H - 1:
        msLst[i][j + 1] = '#'

ansCnt = 0
masLst = [['' for i in range(H)] for j in range(W)]
for i in range(W):
    tmp = input()
    for j in range(len(tmp)):
        masLst[i][j] = tmp[j]

loopBoean = True

while loopBoean:
    jloop = True
    tmp = 0
    msLst = copy.deepcopy(masLst)
    for i in range(W):
        for j in range(H):
            if masLst[i][j] == '#':
                fib(msLst, i, j)
            if masLst[i][j] == '.':
                if tmp == 0:
                    tmp = 1
            if msLst[i][j] != '#':
                jloop = False
    masLst = msLst
    if tmp == 1:
        ansCnt += tmp

    if jloop == True:
        loopBoean = False

print(ansCnt)

Buggy submission (verdict: Runtime Error):
import copy

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

def fib(msLst, i, j):
    if i > 0:
        msLst[i - 1][j] = '#'
    if i < W - 1:
        msLst[i + 1][j] = '#'
    if j > 0:
        msLst[i][j - 1] = '#'
    if j < H - 1:
        msLst[i][j + 1] = '#'

ansCnt = 0
masLst = [['' for i in range(H)] for j in range(W)]
for i in range(W):
    tmp = input()
    for j in range(len(tmp)):
        masLst[i][j] = tmp[j]

loopBoean = True
while loopBoean:
    msLst = copy.deepcopy(masLst)
    for i in range(W):
        for j in range(H):
            if masLst[i][j] == '#':
                fib(msLst, i, j)
    ansCnt += 1
    masLst = msLst

    jloop = True
    for i in range(W):
        for j in range(H):
            if masLst[i][j] != '#':
                jloop = False
                break
        if jloop == False:
            break
    if jloop == True:
        loopBoean = False

print(ansCnt)