Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
f = [input() for _ in range(h)]
ss = []
def bfs(l):
    stack = l
    visited = [[0]*w for i in range(h)]
    dist = [[10**8]*w for i in range(h)]
    vec = [(0,1),(1,0),(-1,0),(0,-1)]
    for sx,sy in l:dist[sx][sy] = 0
    while stack:
        next = []
        for now in stack:
            x,y = now[0],now[1]
            visited[x][y] = 1
            for tx,ty in vec:
                nx,ny = x+tx,y+ty
                if nx < 0 or ny < 0 or nx>h-1 or ny > w-1:continue
                if visited[nx][ny] :continue
                if f[nx][ny] == '#':continue
                next.append((nx,ny))
                dist[nx][ny] = min(dist[nx][ny],dist[x][y] +1)
            stack = next
    res  = 0
    for i in range(h):
        for j in range(w):
            if dist[i][j] == 10**8:continue
            res = max(res,dist[i][j])
    return res


for i in range(h):
    for j in range(w):
        if f[i][j] == '#':ss.append((i,j))
ans  = bfs(ss)
print(ans)



Fixed submission:
h,w = map(int,input().split())
a = list(list(input())for i in range(h))
stack = []
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            stack.append((i,j))
        
vec = ((1,0),(0,1),(-1,0),(0,-1))
move = 0
while stack:
    next = []
    move +=1
    for y,x in stack:
        for ny,nx in vec:
            ty,tx = y+ny,x+nx
            if ty>h-1 or tx>w-1 or ty<0 or tx <0:continue
            if a[ty][tx] == ".":
                a[ty][tx] = move
                next.append((ty,tx))
    stack = next

print(move-1)

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
f = [input() for _ in range(h)]
ss = []
def bfs(l):
    stack = l
    visited = [[0]*w for i in range(h)]
    dist = [[10**8]*w for i in range(h)]
    vec = [(0,1),(1,0),(-1,0),(0,-1)]
    for sx,sy in l:dist[sx][sy] = 0
    while stack:
        next = []
        for now in stack:
            x,y = now[0],now[1]
            visited[x][y] = 1
            for tx,ty in vec:
                nx,ny = x+tx,y+ty
                if nx < 0 or ny < 0 or nx>h-1 or ny > w-1:continue
                if visited[nx][ny] :continue
                if f[nx][ny] == '#':continue
                next.append((nx,ny))
                dist[nx][ny] = min(dist[nx][ny],dist[x][y] +1)
            stack = next
    res  = 0
    for i in range(h):
        for j in range(w):
            if dist[i][j] == 10**8:continue
            res = max(res,dist[i][j])
    return res


for i in range(h):
    for j in range(w):
        if f[i][j] == '#':ss.append((i,j))
ans  = bfs(ss)
print(ans)



Fixed submission:
h,w = map(int,input().split())
a = list(list(input())for i in range(h))
stack = []
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            stack.append((i,j))
        
vec = ((1,0),(0,1),(-1,0),(0,-1))
move = 0
while stack:
    next = []
    move +=1
    for y,x in stack:
        for ny,nx in vec:
            ty,tx = y+ny,x+nx
            if ty>h-1 or tx>w-1 or ty<0 or tx <0:continue
            if a[ty][tx] == ".":
                a[ty][tx] = move
                next.append((ty,tx))
    stack = next

print(move-1)

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
a = list(list(input())for i in range(h))
stack = []
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            stack.append((i,j))
        
vec = ((1,0),(0,1),(-1,0),(0,-1))
move = 0
while stack:
    next = []
    move +=1
    for y,x in stack:
        for ny,nx in vec:
            ty,tx = y+ny,x+nx
            if ty>h-1 or tx>w-1 or ty<0 or tx <0:continue
            if a[ty][tx] == ".":
                a[ty][tx] = move
                next.append((ty,tx))
    stack = next

print(move-1)

Fixed submission:
h,w = map(int,input().split())
a = list(list(input())for i in range(h))
stack = []
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            stack.append((i,j))
        
vec = ((1,0),(0,1),(-1,0),(0,-1))
move = 0
while stack:
    next = []
    move +=1
    for y,x in stack:
        for ny,nx in vec:
            ty,tx = y+ny,x+nx
            if ty>h-1 or tx>w-1 or ty<0 or tx <0:continue
            if a[ty][tx] == ".":
                a[ty][tx] = move
                next.append((ty,tx))
    stack = next

print(move-1)

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
a = list(list(input())for i in range(h))
stack = []
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            stack.append((i,j))
            a[i][j] == -1
vec = ((1,0),(0,1),(-1,0),(0,-1))
move = 0
while stack:
    next = []
    move +=1
    for y,x in stack:
        for ny,nx in vec:
            ty,tx = y+ny,x+nx
            if ty>h-1 or tx>w-1 or ty<0 or tx <0:continue
            if a[ty][tx] == ".":
                a[ty][tx] = move
                next.append((ty,tx))
    stack = next

print(move-1)


Fixed submission:
h,w = map(int,input().split())
a = list(list(input())for i in range(h))
stack = []
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            stack.append((i,j))
        
vec = ((1,0),(0,1),(-1,0),(0,-1))
move = 0
while stack:
    next = []
    move +=1
    for y,x in stack:
        for ny,nx in vec:
            ty,tx = y+ny,x+nx
            if ty>h-1 or tx>w-1 or ty<0 or tx <0:continue
            if a[ty][tx] == ".":
                a[ty][tx] = move
                next.append((ty,tx))
    stack = next

print(move-1)