Buggy python submission (verdict: Time Limit Exceeded):
def main():

    H, W = map(int, input().split())
    A = []
    white = 0
    h = []
    visited = set()
    for i in range(H):
        A.append(input())
        for j in range(W):
            if A[i][j] == '#':
                visited.add((i, j))
                h.append([i, j])
            else:
                white += 1

    cnt = 0
    mv = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    while h and white > 0:
        temp = []
        cnt += 1
        for i, j in h:
            for di, dj in mv:
                i1, j1 = i+di, j+dj
                if 0<=i1<H and 0<=j1<W and (i1, j1) not in visited:
                    temp.append([i1, j1])
                    visited.add((i1, j1))
                    white -= 1
        h = temp
    return cnt

if __name__ == '__main__':
    print(main())

Fixed submission:
import collections
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        A.append(input())
    cur = []
    visited = collections.defaultdict(dict)
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                cur.append([i, j])
                visited[i][j] = 1
            else:
                visited[i][j] = 0
    mv = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    count = 0
    while cur:
        temp = []
        for i, j in cur:
            for di, dj in mv:
                i1, j1 = i+di, j+dj
                if 0 <= i1 < H and 0 <= j1 < W and not visited[i1][j1]:
                    visited[i1][j1] = True
                    temp.append([i1, j1])
        if len(temp) > 0:
            count += 1
        cur = temp
    return count

if __name__ == '__main__':
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        A.append(input())
    cur = []
    visited = dict()
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                cur.append([i, j])
                visited[(i, j)] = 1
            else:
                visited[(i, j)] = 0
    mv = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    count = 0
    while cur:
        temp = []
        for i, j in cur:
            for di, dj in mv:
                i1, j1 = i+di, j+dj
                if 0 <= i1 < H and 0 <= j1 < W and not visited[(i1, j1)]:
                    visited[(i1, j1)] = True
                    temp.append([i1, j1])
        if len(temp) > 0:
            count += 1
        cur = temp
    return count

if __name__ == '__main__':
    print(main())

Fixed submission:
import collections
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        A.append(input())
    cur = []
    visited = collections.defaultdict(dict)
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                cur.append([i, j])
                visited[i][j] = 1
            else:
                visited[i][j] = 0
    mv = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    count = 0
    while cur:
        temp = []
        for i, j in cur:
            for di, dj in mv:
                i1, j1 = i+di, j+dj
                if 0 <= i1 < H and 0 <= j1 < W and not visited[i1][j1]:
                    visited[i1][j1] = True
                    temp.append([i1, j1])
        if len(temp) > 0:
            count += 1
        cur = temp
    return count

if __name__ == '__main__':
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        A.append(input())
    cur = []
    visited = set()
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                heapq.heappush(cur, [0, i, j])
                visited.add((i, j))
    mv = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    max_c = float('-inf')
    while cur:
        c, i, j= heapq.heappop(cur)
        max_c = max(max_c, c)
        for di, dj in mv:
            i1, j1 = i+di, j+dj
            if (i1, j1) not in visited and 0 <= i1 < H and 0 <= j1 < W:
                visited.add((i1, j1))
                heapq.heappush(cur, [c+1, i1, j1])
    return max_c

if __name__ == '__main__':
    print(main())

Fixed submission:
import collections
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        A.append(input())
    cur = []
    visited = collections.defaultdict(dict)
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                cur.append([i, j])
                visited[i][j] = 1
            else:
                visited[i][j] = 0
    mv = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    count = 0
    while cur:
        temp = []
        for i, j in cur:
            for di, dj in mv:
                i1, j1 = i+di, j+dj
                if 0 <= i1 < H and 0 <= j1 < W and not visited[i1][j1]:
                    visited[i1][j1] = True
                    temp.append([i1, j1])
        if len(temp) > 0:
            count += 1
        cur = temp
    return count

if __name__ == '__main__':
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        A.append(input())
    cur = []
    visited = set()
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                cur.append([i, j])
                visited.add((i, j))
    mv = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    count = 0
    while cur:
        temp = []
        for i, j in cur:
            for di, dj in mv:
                i1, j1 = i+di, j+dj
                if (i1, j1) not in visited and 0 <= i1 < H and 0 <= j1 < W:
                    visited.add((i1, j1))
                    temp.append([i1, j1])
        if len(temp) > 0:
            count += 1
        cur = temp
    return count

if __name__ == '__main__':
    print(main())

Fixed submission:
import collections
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        A.append(input())
    cur = []
    visited = collections.defaultdict(dict)
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                cur.append([i, j])
                visited[i][j] = 1
            else:
                visited[i][j] = 0
    mv = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    count = 0
    while cur:
        temp = []
        for i, j in cur:
            for di, dj in mv:
                i1, j1 = i+di, j+dj
                if 0 <= i1 < H and 0 <= j1 < W and not visited[i1][j1]:
                    visited[i1][j1] = True
                    temp.append([i1, j1])
        if len(temp) > 0:
            count += 1
        cur = temp
    return count

if __name__ == '__main__':
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        A.append(input())
    cur = []
    visited = set()
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                cur.append([i, j])
                visited.add((i, j))
    mv = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    count = 0
    while cur:
        temp = []
        for i, j in cur:
            for di, dj in mv:
                i1, j1 = i+di, j+dj
                if (i1, j1) not in visited and 0 <= i1 < H and 0 <= j1 < W:
                    visited.add((i1, j1))
                    temp.append([i1, j1])
        if len(temp) > 0:
            count += 1
        cur = temp
    return count

if __name__ == '__main__':
    print(main())

Fixed submission:
import collections
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        A.append(input())
    cur = []
    visited = collections.defaultdict(dict)
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                cur.append([i, j])
                visited[i][j] = 1
            else:
                visited[i][j] = 0
    mv = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    count = 0
    while cur:
        temp = []
        for i, j in cur:
            for di, dj in mv:
                i1, j1 = i+di, j+dj
                if 0 <= i1 < H and 0 <= j1 < W and not visited[i1][j1]:
                    visited[i1][j1] = True
                    temp.append([i1, j1])
        if len(temp) > 0:
            count += 1
        cur = temp
    return count

if __name__ == '__main__':
    print(main())