Buggy python submission (verdict: Time Limit Exceeded):
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        a = input()
        A.append(a)
    bl = set()
    wl = set()
    for i in range(H):
        for j in range(W):
            if A[i][j] == '#':
                bl.add((i, j))
            else:
                wl.add((i, j))
    r = 0
    while wl:
        bln = set()
        for i in bl:
            if (i[0] + 1, i[1]) in wl:
                wl.remove((i[0] + 1, i[1]))
                bln.add((i[0] + 1, i[1]))
            if (i[0] - 1, i[1]) in wl:
                wl.remove((i[0] - 1, i[1]))
                bln.add((i[0] - 1, i[1]))
            if (i[0], i[1] + 1) in wl:
                wl.remove((i[0], i[1] + 1))
                bln.add((i[0], i[1] + 1))
            if (i[0], i[1] - 1) in wl:
                wl.remove((i[0], i[1] - 1))
                bln.add((i[0], i[1] - 1))
        bl = bln
        r += 1
    return r
print(main())


Fixed submission:
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        a = input()
        A.append(a)
    bl = []
    wl = set()
    for i in range(H):
        for j in range(W):
            if A[i][j] == '#':
                bl.append((i, j))
            else:
                wl.add((i, j))
    r = 0
    while wl:
        bln = []
        for i in bl:
            if (i[0] + 1, i[1]) in wl:
                wl.remove((i[0] + 1, i[1]))
                bln.append((i[0] + 1, i[1]))
            if (i[0] - 1, i[1]) in wl:
                wl.remove((i[0] - 1, i[1]))
                bln.append((i[0] - 1, i[1]))
            if (i[0], i[1] + 1) in wl:
                wl.remove((i[0], i[1] + 1))
                bln.append((i[0], i[1] + 1))
            if (i[0], i[1] - 1) in wl:
                wl.remove((i[0], i[1] - 1))
                bln.append((i[0], i[1] - 1))
        bl = bln
        r += 1
    return r
print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        a = input()
        A.append(a)
    bl = []
    wl = []
    for i in range(H):
        for j in range(W):
            if A[i][j] == '#':
                bl.append((i, j))
            else:
                wl.append((i, j))
    r = 0
    for i in wl:
        t = 10**9
        for j in bl:
            t = min(t, abs(i[0]-j[0]) + abs(i[1]-j[1]))
        r = max(r, t)
    return r
print(main())


Fixed submission:
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        a = input()
        A.append(a)
    bl = []
    wl = set()
    for i in range(H):
        for j in range(W):
            if A[i][j] == '#':
                bl.append((i, j))
            else:
                wl.add((i, j))
    r = 0
    while wl:
        bln = []
        for i in bl:
            if (i[0] + 1, i[1]) in wl:
                wl.remove((i[0] + 1, i[1]))
                bln.append((i[0] + 1, i[1]))
            if (i[0] - 1, i[1]) in wl:
                wl.remove((i[0] - 1, i[1]))
                bln.append((i[0] - 1, i[1]))
            if (i[0], i[1] + 1) in wl:
                wl.remove((i[0], i[1] + 1))
                bln.append((i[0], i[1] + 1))
            if (i[0], i[1] - 1) in wl:
                wl.remove((i[0], i[1] - 1))
                bln.append((i[0], i[1] - 1))
        bl = bln
        r += 1
    return r
print(main())