Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(100000)
h,w=map(int,input().split())
a_list=[]
for i in range(h):
    b=list(input())
    a_list.append(b)
dp=[]
for i in range(h):
    dps=[]
    for j in range(w):
        dps.append(10**9)
    dp.append(dps)
def f(x,y):
    if dp[x][y]<10**9:
        return dp[x][y]
    else:
        if a_list[x][y]=='#':
            dp[x][y]=0
            return 0
        else:
            dp[x][y]=10**8
            if x>0:
                k0=f(x-1,y)+1
            else:
                k0=10**9
            if x<h-1:
                k1=f(x+1,y)+1
            else:
                k1=10**9
            if y>0:
                k2=f(x,y-1)+1
            else:
                k2=10**9
            if y<w-1:
                k3=f(x,y+1)+1
            else:
                k3=10**9
            m=min(k0,k1,k2,k3)
            dp[x][y]=m
            return m
answer=0
for i in range(h):
    for j in range(w):
        answer=max(answer,f(i,j))
print(answer)

        


Fixed submission:
from collections import deque
h,w=map(int,input().split())
INF=10**9
check=[]
for i in range(h):
    sub_list=[]
    for j in range(w):
        sub_list.append(INF)
    check.append(sub_list)
black=deque([])
for i in range(h):
    sub_list=list(input())
    for j in range(w):
        if sub_list[j]=='#':
            black.append((i,j))
            check[i][j]=0
Max=0
while len(black)>0:
    now=black.popleft()
    U=(now[0]-1,now[1])
    D=(now[0]+1,now[1])
    L=(now[0],now[1]-1)
    R=(now[0],now[1]+1)
    for i in U,D,L,R:
        if 0<=i[0]<=h-1 and 0<=i[1]<=w-1 and check[i[0]][i[1]]==INF:
            check[i[0]][i[1]]=check[now[0]][now[1]]+1
            Max=max(Max,check[i[0]][i[1]])
            black.append(i)
print(Max)

Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
a_list=[]
for i in range(h):
    b=list(input())
    a_list.append(b)
dp=[]
for i in range(h):
    dps=[]
    for j in range(w):
        dps.append(10**9)
    dp.append(dps)
def f(x,y):
    if dp[x][y]<10**9:
        return dp[x][y]
    else:
        if a_list[x][y]=='#':
            dp[x][y]=0
            return 0
        else:
            dp[x][y]=10**8
            if x>0:
                k0=f(x-1,y)+1
            else:
                k0=10**9
            if x<h-1:
                k1=f(x+1,y)+1
            else:
                k1=10**9
            if y>0:
                k2=f(x,y-1)+1
            else:
                k2=10**9
            if y<w-1:
                k3=f(x,y+1)+1
            else:
                k3=10**9
            m=min(k0,k1,k2,k3)
            dp[x][y]=m
            return m
answer=0
for i in range(h):
    for j in range(w):
        answer=max(answer,f(i,j))
print(answer)

        


Fixed submission:
from collections import deque
h,w=map(int,input().split())
INF=10**9
check=[]
for i in range(h):
    sub_list=[]
    for j in range(w):
        sub_list.append(INF)
    check.append(sub_list)
black=deque([])
for i in range(h):
    sub_list=list(input())
    for j in range(w):
        if sub_list[j]=='#':
            black.append((i,j))
            check[i][j]=0
Max=0
while len(black)>0:
    now=black.popleft()
    U=(now[0]-1,now[1])
    D=(now[0]+1,now[1])
    L=(now[0],now[1]-1)
    R=(now[0],now[1]+1)
    for i in U,D,L,R:
        if 0<=i[0]<=h-1 and 0<=i[1]<=w-1 and check[i[0]][i[1]]==INF:
            check[i[0]][i[1]]=check[now[0]][now[1]]+1
            Max=max(Max,check[i[0]][i[1]])
            black.append(i)
print(Max)

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
a_list=[]
for i in range(h):
    b=list(input())
    a_list.append(b)
count=-1
end=0
while end==0:
    end=1
    c_list=[]
    for i in range(h):
        for j in range(w):
            if a_list[i][j]=='#':
                if i>0:
                    c_list.append((i-1,j))
                if i<h-1:
                    c_list.append((i+1,j))
                if j>0:
                    c_list.append((i,j-1))
                if j<w-1:
                    c_list.append((i,j+1))
            else:
                end=0
    for k in c_list:
        a_list[k[0]][k[1]]='#'
    count=count+1
print(count)


Fixed submission:
from collections import deque
h,w=map(int,input().split())
INF=10**9
check=[]
for i in range(h):
    sub_list=[]
    for j in range(w):
        sub_list.append(INF)
    check.append(sub_list)
black=deque([])
for i in range(h):
    sub_list=list(input())
    for j in range(w):
        if sub_list[j]=='#':
            black.append((i,j))
            check[i][j]=0
Max=0
while len(black)>0:
    now=black.popleft()
    U=(now[0]-1,now[1])
    D=(now[0]+1,now[1])
    L=(now[0],now[1]-1)
    R=(now[0],now[1]+1)
    for i in U,D,L,R:
        if 0<=i[0]<=h-1 and 0<=i[1]<=w-1 and check[i[0]][i[1]]==INF:
            check[i[0]][i[1]]=check[now[0]][now[1]]+1
            Max=max(Max,check[i[0]][i[1]])
            black.append(i)
print(Max)