Problem p03053 (python)

Fixed submission:
from collections import deque
from copy import copy

row, column = map(int, input().split())
map_ = [[c == "#" for c in input().strip()] for _ in range(row)]

queue = deque([(i, j) for j in range(column) for i in range(row) if map_[i][j]])

def bfs(maze, queue):
    depth = 0
    while True:
        depth += 1
        nextqueue = deque()
        while queue:
            posr, posc = queue.popleft()
            for dr, dc in zip([1, -1, 0, 0], [0, 0, 1, -1]):
                nextr = posr + dr
                nextc = posc + dc
                if 0 <= nextr < row and 0 <= nextc < column and not maze[nextr][nextc]:
                    maze[nextr][nextc] = True
                    nextqueue.append((nextr, nextc))
        if nextqueue:
            queue = copy(nextqueue)
        else:
            return depth - 1

print(bfs(map_, queue))

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

r, c = map(int, input().split())
map_ = [[c == "#" for c in input().strip()] for _ in range(r)]

queue = deque([(i, j) for j in range(r) for i in range(c) if map_[i][j]])

def bfs(maze, queue):
    depth = 0
    while True:
        depth += 1
        nextqueue = deque()
        while queue:
            posr, posc = queue.popleft()
            for dr, dc in zip([1, -1, 0, 0], [0, 0, 1, -1]):
                nextr = posr + dr
                nextc = posc + dc
                if 0 <= nextr < r and 0 <= nextc < c and not maze[nextr][nextc]:
                    maze[nextr][nextc] = True
                    nextqueue.append((nextr, nextc))
        if nextqueue:
            queue = copy(nextqueue)
        else:
            return depth - 1


print(bfs(map_, queue))

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

r, c = map(int, input().split())
maze = [[True] * (c + 2)] + [[True] + [c == "#" for c in input().strip()] + [True] for _ in range(r)] + [[True] * (c + 2)]

queue = deque([(i, j) for j in range(1, r + 1) for i in range(1, c + 1) if maze[i][j]])

def BFS(maze, queue):
    depth = 0

    while True:
        depth += 1
        nextqueue = deque()
        while queue:
            posr, posc = queue.popleft()
            if not maze[posr + 1][posc]:
                maze[posr + 1][posc] = True
                nextqueue.append((posr + 1, posc))
            if not maze[posr - 1][posc]:
                maze[posr - 1][posc] = True
                nextqueue.append((posr - 1, posc))
            if not maze[posr][posc + 1]:
                maze[posr][posc + 1] = True
                nextqueue.append((posr, posc + 1))
            if not maze[posr][posc - 1]:
                maze[posr][posc - 1] = True
                nextqueue.append((posr, posc - 1))

        if not nextqueue:
            return depth - 1
        else:
            queue = copy(nextqueue)


print(BFS(maze, queue))

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

r, c = map(int, input().strip().split())
maze = [["#"] * (c + 2)] + [["#"] + list(input().strip()) + ["#"] for _ in range(r)] + [["#"] * (c + 2)]

queue = deque([(i, j) for j in range(1, r + 1) for i in range(1, c + 1) if maze[i][j] == "#"])

def BFS(maze, queue):
    depth = 0
    nextqueue = deque()

    while queue:
        depth += 1
        while queue:
            posr, posc = queue.popleft()
            for r, c in zip([1, -1, 0, 0], [0, 0, 1, -1]):
                nextr = posr + r
                nextc = posc + c
                terrein = maze[nextr][nextc]
                if terrein == ".":
                    maze[nextr][nextc] = "#"
                    nextqueue.append((nextr, nextc))
        queue = copy(nextqueue)
        nextqueue.clear()

    return depth - 1

print(BFS(maze, queue))

Buggy submission (verdict: Runtime Error):

from collections import deque

r, c = map(int, input().strip().split())
maze = [[0] * (c + 2)] + [[0] + [0 if c == "#" else float("inf") for c in input().strip()] + [0] for _ in range(r)] + [[0] * (c + 2)]

queue = deque([(i, j) for j in range(1, r + 1) for i in range(1, c + 1) if maze[i][j] == 0])

def BFS_maze(maze, queue):
    depth = 0
    nextqueue = deque()

    while queue:
        depth += 1
        while queue:
            posr, posc = queue.popleft()
            for r, c in zip([1, -1, 0, 0], [0, 0, 1, -1]):
                nextr = posr + r
                nextc = posc + c
                terrein = maze[nextr][nextc]
                if terrein > depth:
                    maze[nextr][nextc] = depth
                    nextqueue.append((nextr, nextc))
        queue = nextqueue
        nextqueue = deque()

BFS_maze(maze, queue)
print(max(inner for outer in maze for inner in outer))

Buggy submission (verdict: Runtime Error):
r, c = map(int, input().strip().split())
maze = [[0] * (c + 2)] + [[0] + [0 if c == "#" else 2001 for c in input().strip()] + [0] for _ in range(r)] + [[0] * (c + 2)]
queue = [(i, j) for j in range(1, r + 1) for i in range(1, c + 1) if maze[i][j] == 0]

def BFS_maze(maze, queue):
    depth = 0
    nextqueue = []

    while queue:
        depth += 1
        for pos in queue:
            posr, posc = pos
            for r, c in zip([1, -1, 0, 0], [0, 0, 1, -1]):
                nextr = posr + r
                nextc = posc + c
                terrein = maze[nextr][nextc]
                if terrein > depth:
                    maze[nextr][nextc] = depth
                    nextqueue.append((nextr, nextc))
        queue = nextqueue[:]
        nextqueue.clear()

BFS_maze(maze, queue)
print(max(inner for outer in maze for inner in outer))