Buggy python submission (verdict: Time Limit Exceeded):
H, W = list(map(int, input().split()))
 
start = []
c = []
for y in range(H):
    c.append(input())
    for x in range(W):
        if c[-1][x]=='#':
            start.append([y,x])
            
visited = [0 for _ in range(W*H)]
for one in start:
    visited[one[0]*W+one[1]] = 1
    
cnt = 0
while sum(visited)!=W*H:
    tmp_s = []
    for one in start:
        cy,cx = one
        for dy, dx in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            ny, nx = cy+dy, cx+dx
            if 0 <= nx < W and 0 <= ny < H and visited[ny*W+nx]==0:
                visited[ny*W+nx] = 1
                tmp_s.append([ny,nx])
    cnt+=1
    start = tmp_s
print(cnt)  

Fixed submission:
def main():
    H, W = list(map(int, input().split()))
    c = [input() for j in range(H)]
    from collections import deque
    que = deque()
    dist = [[-1]*W for i in range(H)]
    for h in range(H):
        for w in range(W):
            if c[h][w] == "#":
                que.append((h, w))
                dist[h][w] = 0
 
    def bfs():
        d = ((1, 0), (0, 1), (-1, 0), (0, -1))
        while que:
            # popleftにすれば、手の短い方が優先されているので、それで訪れられる所は全て確定でいい。
            # 探索するところが無くなるまで続ける。
            cy, cx = que.popleft()
            for dy, dx in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                ny, nx = cy+dy, cx+dx
                if 0 <= ny < H and 0 <= nx < W and dist[ny][nx] == -1 and c[ny][nx] == '.':
                    dist[ny][nx] = dist[cy][cx] + 1
                    que.append((ny, nx))
 
    bfs()
    ans = 0
    for h in range(H):
        for w in range(W):
            ans = max(ans, dist[h][w])
    print(ans)
 
 
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
H, W = list(map(int, input().split()))
 
start = []
c = []
for y in range(H):
    c.append(input())
    for x in range(W):
        if c[-1][x]=='#':
            start.append([y,x])
            
visited = [0 for _ in range(W*H)]
for one in start:
    visited[one[0]*W+one[1]] = 1
    
cnt = 0
while sum(visited)!=W*H:
    tmp_s = []
    for one in start:
        cy,cx = one
        for dy, dx in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            ny, nx = cy+dy, cx+dx
            if 0 <= nx < W and 0 <= ny < H and visited[ny*W+nx]==0:
                visited[ny*W+nx] = 1
                tmp_s.append([ny,nx])
    cnt+=1
    start = tmp_s
print(cnt)  

Fixed submission:
def main():
    H, W = list(map(int, input().split()))
    c = [input() for j in range(H)]
    from collections import deque
    que = deque()
    dist = [[-1]*W for i in range(H)]
    for h in range(H):
        for w in range(W):
            if c[h][w] == "#":
                que.append((h, w))
                dist[h][w] = 0
 
    def bfs():
        d = ((1, 0), (0, 1), (-1, 0), (0, -1))
        while que:
            # popleftにすれば、手の短い方が優先されているので、それで訪れられる所は全て確定でいい。
            # 探索するところが無くなるまで続ける。
            cy, cx = que.popleft()
            for dy, dx in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                ny, nx = cy+dy, cx+dx
                if 0 <= ny < H and 0 <= nx < W and dist[ny][nx] == -1 and c[ny][nx] == '.':
                    dist[ny][nx] = dist[cy][cx] + 1
                    que.append((ny, nx))
 
    bfs()
    ans = 0
    for h in range(H):
        for w in range(W):
            ans = max(ans, dist[h][w])
    print(ans)
 
 
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
H, W = list(map(int, input().split()))

start = []
c = []
for y in range(H):
    c.append(input())
    for x in range(W):
        if c[-1][x]=='#':
            start.append([y,x])
            
visited = [0 for _ in range(W*H)]
cnt = 0
while sum(visited)!=W*H:
    tmp_s = []
    for one in start:
        cy,cx = one
        for dy, dx in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            ny, nx = cy+dy, cx+dx
            if 0 <= nx < W and 0 <= ny < H and visited[ny*W+nx]==0:
                visited[ny*W+nx] = 1
                tmp_s.append([ny,nx])
    cnt+=1
    start = tmp_s
print(cnt)  

Fixed submission:
def main():
    H, W = list(map(int, input().split()))
    c = [input() for j in range(H)]
    from collections import deque
    que = deque()
    dist = [[-1]*W for i in range(H)]
    for h in range(H):
        for w in range(W):
            if c[h][w] == "#":
                que.append((h, w))
                dist[h][w] = 0
 
    def bfs():
        d = ((1, 0), (0, 1), (-1, 0), (0, -1))
        while que:
            # popleftにすれば、手の短い方が優先されているので、それで訪れられる所は全て確定でいい。
            # 探索するところが無くなるまで続ける。
            cy, cx = que.popleft()
            for dy, dx in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                ny, nx = cy+dy, cx+dx
                if 0 <= ny < H and 0 <= nx < W and dist[ny][nx] == -1 and c[ny][nx] == '.':
                    dist[ny][nx] = dist[cy][cx] + 1
                    que.append((ny, nx))
 
    bfs()
    ans = 0
    for h in range(H):
        for w in range(W):
            ans = max(ans, dist[h][w])
    print(ans)
 
 
if __name__ == '__main__':
    main()