Problem p03053 (python)

Fixed submission:
from collections import deque


H, W = map(int, input().split())
A = [list('#' * (W + 2))]
q = deque()
A_append = A.append
q_append = q.append
for _ in range(H):
    a = input()
    A_append(list('#' + a + '#'))
A.append(list('#' * (W + 2)))
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if A[i][j] == '#':
            q_append([i, j, 0])

ans = 0

while len(q) != 0:
    p = q.popleft()
    for k in range(4):
        y = p[0] + dy[k]
        x = p[1] + dx[k]
        c = p[2]
        ans = max(ans, c)
        if A[y][x] == '.':
            A[y][x] = '#'
            q_append([y, x, c + 1])

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque


H, W = map(int, input().split())
A = [list('#' * (W + 2))]
q = deque()
A_append = A.append
q_append = q.append
for _ in range(H):
    a = input()
    A_append(list('#' + a + '#'))
A.append(list('#' * (W + 2)))
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if A[i][j] == '#':
            q_append([i, j, 0])

ans = 0

while len(q) != 0:
    p = q.popleft()
    for k in range(4):
        y = p[1] + dy[k]
        x = p[0] + dx[k]
        c = p[2]
        ans = max(ans, c)
        if A[y][x] == '.':
            A[y][x] = '#'
            q_append([y, x, c + 1])

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque

H, W = map(int, input().split())
A = [list('#' * (W + 2))]
q = deque()
for _ in range(H):
    a = input()
    A.append(list('#' + a + '#'))
A.append(list('#' * (W + 2)))
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if A[i][j] == '#':
            q.append([i, j, 1])

ans = 1

while len(q) != 0:
    p = q.popleft()
    for k in range(4):
        y = p[1] + dy[k]
        x = p[0] + dx[k]
        c = p[2]
        ans = max(ans, c)
        if A[y][x] == '.':
            A[y][x] = '#'
            q.append([y, x, c + 1])

print(ans - 1)

Buggy submission (verdict: Runtime Error):
from collections import deque

H, W = map(int, input().split())
A = [list('#' * (W + 2))]
q = deque()
for _ in range(H):
    a = input()
    A.append(list('#' + a + '#'))
A.append(list('#' * (W + 2)))
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if A[i][j] == '#':
            q.append([i, j, 1])

ans = 0

while len(q) != 0:
    p = q.popleft()
    for k in range(4):
        y = p[1] + dy[k]
        x = p[0] + dx[k]
        c = p[2]
        ans = max(ans, c)
        if A[y][x] == '.':
            A[y][x] = '#'
            q.append([y, x, c + 1])

print(ans - 1)

Buggy submission (verdict: Runtime Error):
import copy
import queue

H, W = map(int, input().split())
A = [list('#' * (W + 2))]
q = queue.Queue()
for _ in range(H):
    a = input()
    A.append(list('#' + a + '#'))
A.append(list('#' * (W + 2)))
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if A[i][j] == '#':
            q.put([i, j, 1])

ans = 0

while not q.empty():
    p = q.get()
    for k in range(4):
        y = p[1] + dy[k]
        x = p[0] + dx[k]
        c = p[2]
        ans = max(ans, c)
        if A[y][x] == '.':
            A[y][x] = '#'
            q.put([y, x, c + 1])

print(ans - 1)

Buggy submission (verdict: Runtime Error):
import copy
import queue

H, W = map(int, input().split())
A = [list('#' * (W + 2))]
q = queue.Queue()
for _ in range(H):
    a = input()
    A.append(list('#' + a + '#'))
A.append(list('#' * (W + 2)))
B = copy.deepcopy(A)
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if A[i][j] == '#':
            q.put([i, j])
q.put([])

ans = 0
count = 0
while not q.empty():
    count = 0
    p = q.get()
    if p == []:
        ans += 1
        A = copy.deepcopy(B)
        if not q.empty():
            q.put([])
    else:
        for k in range(4):
            y = p[1] + dy[k]
            x = p[0] + dx[k]
            if A[y][x] == '.':
                B[y][x] = '#'
                q.put([y, x])

print(ans - 1)

Buggy submission (verdict: Runtime Error):
import copy
import queue

H, W = map(int, input().split())
A = [list('#' * (W + 2))]
q = queue.Queue()
for _ in range(H):
    a = input()
    A.append(list('#' + a + '#'))
A.append(list('#' * (W + 2)))
B = copy.deepcopy(A)
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if A[i][j] == '#':
            q.put([i, j])
q.put([])

ans = 0
count = 0
while not q.empty():
    count = 0
    p = q.get()
    if p == []:
        ans += 1
        A = copy.deepcopy(B)
        if not q.empty():
            q.put([])
    else:
        for k in range(4):
            y = p[1] + dy[k]
            x = p[0] + dx[k]
            if A[y][x] == '.':
                B[y][x] = '#'
                q.put([y, x])

print(ans - 1)