Problem p03053 (python)

Fixed submission:
h, w = map(int, input().split())

grid = [[True] * (w + 2)]
for _ in range(h):
    grid.append([True] + [x == '#' for x in input()] + [True])
grid.append([True] * (w + 2))

q = []

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if grid[i][j] is True:
            q.append((i, j))

cnt = 0
while q:
    qq = []
    for i, j in q:
        if not grid[i + 1][j]:
            grid[i + 1][j] = True
            qq.append((i + 1, j))
        if not grid[i - 1][j]:
            grid[i - 1][j] = True
            qq.append((i - 1, j))
        if not grid[i][j + 1]:
            grid[i][j + 1] = True
            qq.append((i, j + 1))
        if not grid[i][j - 1]:
            grid[i][j - 1] = True
            qq.append((i, j - 1))

    cnt += 1
    q = qq

print(cnt - 1)

Buggy submission (verdict: Runtime Error):
import copy

h, w = map(int, input().split())

grid = [[False] * (w + 2)]
for _ in range(w):
    grid.append([False] + [x == '#' for x in input()] + [False])
grid.append([False] * (w + 2))

cnt = 0
while True:
    flag = True
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            # print('#' if grid[i][j] else '.', end='')
            if grid[i][j] is False:
                flag = False
        # print()
    if flag:
        break

    new_grid = copy.deepcopy(grid)
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if grid[i][j] is True:
                new_grid[i][j + 1] = True
                new_grid[i][j - 1] = True
                new_grid[i + 1][j] = True
                new_grid[i - 1][j] = True
    grid = new_grid
    cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
import numpy as np

h, w = map(int, input().split())

grid = [[False] * (w + 2)]
for _ in range(w):
    grid.append([False] + [x == '#' for x in input()] + [False])
grid.append([False] * (w + 2))

grid = np.array(grid)

cnt = 0
while True:
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            print('#' if grid[i, j] else '.', end='')
        print()
    if np.all(grid[1:-1, 1:-1]):
        break

    new_grid = grid.copy()
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if grid[i][j] == 0:
                if grid[i + 1, j] or grid[i, j + 1] or grid[i - 1, j] or grid[i, j - 1]:
                    new_grid[i][j] = 1
    grid = new_grid
    cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
import copy

h, w = map(int, input().split())

grid = [[False] * (w + 2)]
for _ in range(w):
    grid.append([False] + [x == '#' for x in input()] + [False])
grid.append([False] * (w + 2))

cnt = 0
while True:
    flag = True
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            # print('#' if grid[i][j] else '.', end='')
            if grid[i][j] is False:
                flag = False
        # print()
    if flag:
        break

    new_grid = copy.deepcopy(grid)
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if grid[i][j] is False:
                if grid[i + 1][j] or grid[i][j + 1] or grid[i - 1][j] or grid[i][j - 1]:
                    new_grid[i][j] = True
    grid = new_grid
    cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())

grid = []
for _ in range(w):
    grid.append([x == '#' for x in input()])

maxd = 0
for i in range(h):
    for j in range(w):
        if grid[i][j] is False:
            mind = 10000000
            for ii in range(h):
                for jj in range(w):
                    if grid[ii][jj] is True:
                        d = abs(i - ii) + abs(j - jj)
                        if d < mind:
                            mind = d
            if mind > maxd:
                maxd = mind

print(maxd)