Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
def main():
    H,W = map(int,input().split())
    masu = [list(input()) for _ in range(H)]
    def bfs():
        que = deque()
        seen = [[0]*(W+2)] + [[0] + [1]*(W)+[0]  for _ in range(H)] +[[0]*(W+2)] 
        for w in range(W):
            for h in range(H):
                if masu[h][w] == '#':
                    que.append((w,h,0))
                    seen[h+1][w+1] =0
        while que:
            a,b,k = que.popleft()
            for x,y in [[0,1],[1,0],[0,-1],[-1,0]]:
                nx = a+x
                ny = b+y
                if seen[ny+1][nx+1]:
                    seen[ny+1][nx+1] = 0
                    que.append((nx,ny,k+1))
        return k
    print(bfs())
if __name__ == '__main__':
    main()

Fixed submission:
from collections import deque
 
def solve(h, w, a):
    used = [[True] * (w+2) for _ in range(h+2)]
    que = deque()
    for r in range(h):
        used[r+1][1:-1] = map(lambda _:_=="#", a[r])
        for c in range(w):
            if a[r][c] == "#":
                que.append((r+1, c+1, 0))
    neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
    while que:
        r, c, k = que.popleft()
        for dr, dc in neighbors:
            nr, nc = r+dr, c+dc
            if not used[nr][nc]:
                que.append((nr, nc, k+1))
                used[nr][nc] = True
    return k
 
h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(solve(h, w, a))

Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int,input().split())
masu = [list(input()) for _ in range(H)]
from collections import deque
def bfs():
    que = deque()
    seen = [[0]*(W+2)] + [[0] + [1]*(W)+[0]  for _ in range(H)] +[[0]*(W+2)] 
    for w in range(W):
        for h in range(H):
            if masu[h][w] == '#':
                que.append((w,h,0))
                seen[h+1][w+1] =0
    while que:
        a,b,k = que.popleft()
        for x,y in [[0,1],[1,0],[0,-1],[-1,0]]:
            nx = a+x
            ny = b+y
            if seen[ny+1][nx+1]:
                seen[ny+1][nx+1] = 0
                que.append((nx,ny,k+1))
    return k
print(bfs())

Fixed submission:
from collections import deque
 
def solve(h, w, a):
    used = [[True] * (w+2) for _ in range(h+2)]
    que = deque()
    for r in range(h):
        used[r+1][1:-1] = map(lambda _:_=="#", a[r])
        for c in range(w):
            if a[r][c] == "#":
                que.append((r+1, c+1, 0))
    neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
    while que:
        r, c, k = que.popleft()
        for dr, dc in neighbors:
            nr, nc = r+dr, c+dc
            if not used[nr][nc]:
                que.append((nr, nc, k+1))
                used[nr][nc] = True
    return k
 
h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(solve(h, w, a))

Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int,input().split())
masu = [list(input()) for _ in range(H)]
from collections import deque
def bfs():
    que = deque()
    seen = [[0]*(W+2)] + [[0] + [-1]*(W)+[0]  for _ in range(H)] +[[0]*(W+2)] 
    for w in range(W):
        for h in range(H):
            if masu[h][w] == '#':
                que.append((w,h))
                seen[h+1][w+1] =0
    while que:
        a,b = que.popleft()
        for x,y in [[0,1],[1,0],[0,-1],[-1,0]]:
            nx = a+x
            ny = b+y
            if seen[ny+1][nx+1] == -1:
                seen[ny+1][nx+1] = seen[b+1][a+1]+1
                que.append((nx,ny))
    ans = max(map(max,seen))
    return ans
print(bfs())

Fixed submission:
from collections import deque
 
def solve(h, w, a):
    used = [[True] * (w+2) for _ in range(h+2)]
    que = deque()
    for r in range(h):
        used[r+1][1:-1] = map(lambda _:_=="#", a[r])
        for c in range(w):
            if a[r][c] == "#":
                que.append((r+1, c+1, 0))
    neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
    while que:
        r, c, k = que.popleft()
        for dr, dc in neighbors:
            nr, nc = r+dr, c+dc
            if not used[nr][nc]:
                que.append((nr, nc, k+1))
                used[nr][nc] = True
    return k
 
h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(solve(h, w, a))

Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int,input().split())
masu = [list(input()) for _ in range(H)]
from collections import deque
def bfs():
    que = deque([])
    seen = [[0]*(W+2)] + [[0] + [float('inf')]*(W)+[0]  for _ in range(H)] +[[0]*(W+2)] 
    for w in range(W):
        for h in range(H):
            if masu[h][w] == '#':
                que.append((w,h))
                seen[h+1][w+1] =0
    while que:
        a,b = que.popleft()
        for x,y in [[0,1],[1,0],[0,-1],[-1,0]]:
            nx = a+x
            ny = b+y
            if seen[ny+1][nx+1] == float('inf') and masu[ny][nx] == '.':
                seen[ny+1][nx+1] = seen[b+1][a+1] +1
                que.append((nx,ny))
    ans = 0
    for i in range(H+2):
        for j in range(W+2):
            if seen[i][j] > ans:
                ans = seen[i][j]
    return ans
print(bfs())

Fixed submission:
from collections import deque
 
def solve(h, w, a):
    used = [[True] * (w+2) for _ in range(h+2)]
    que = deque()
    for r in range(h):
        used[r+1][1:-1] = map(lambda _:_=="#", a[r])
        for c in range(w):
            if a[r][c] == "#":
                que.append((r+1, c+1, 0))
    neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
    while que:
        r, c, k = que.popleft()
        for dr, dc in neighbors:
            nr, nc = r+dr, c+dc
            if not used[nr][nc]:
                que.append((nr, nc, k+1))
                used[nr][nc] = True
    return k
 
h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(solve(h, w, a))

Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int,input().split())
masu = [list(input()) for _ in range(H)]
from collections import deque
def bfs():
    que = deque([])
    seen = [[float('inf')]*W for _ in range(H)]
    for w in range(W):
        for h in range(H):
            if masu[h][w] == '#':
                que.append((w,h))
                seen[h][w] =0
    while que:
        a,b = que.popleft()
        for x,y in [[0,1],[1,0],[0,-1],[-1,0]]:
            nx = a+x
            ny = b+y
            if 0<=nx<W and 0<=ny<H and seen[ny][nx] == float('inf') and masu[ny][nx] != '#':
                seen[ny][nx] = seen[b][a] +1
                que.append((nx,ny))
    ans = 0
    for i in range(H):
        for j in range(W):
            if seen[i][j] > ans:
                ans = seen[i][j]
    return ans
print(bfs())

Fixed submission:
from collections import deque
 
def solve(h, w, a):
    used = [[True] * (w+2) for _ in range(h+2)]
    que = deque()
    for r in range(h):
        used[r+1][1:-1] = map(lambda _:_=="#", a[r])
        for c in range(w):
            if a[r][c] == "#":
                que.append((r+1, c+1, 0))
    neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
    while que:
        r, c, k = que.popleft()
        for dr, dc in neighbors:
            nr, nc = r+dr, c+dc
            if not used[nr][nc]:
                que.append((nr, nc, k+1))
                used[nr][nc] = True
    return k
 
h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(solve(h, w, a))