Buggy python submission (verdict: Time Limit Exceeded):
def main():
    h,w = map(int,input().split())
    a=[]
    que=[]
    for _ in range(h):
        a.append(list(input()))
    for i in range(h):
        for j in range(w):
            if a[i][j]=="#":
                que.append([i,j])
                a[i][j]=0
    ans=0
    while que!=[]:
        [i,j]=que[0]
        que.pop(0)
        if j<w-1 and a[i][j+1]==".":
            que.append([i,j+1])
            a[i][j+1]=a[i][j]+1
            if ans < a[i][j]+1:
                ans=a[i][j]+1
        if 0<j and a[i][j-1]==".":
            que.append([i,j-1])
            a[i][j-1]=a[i][j]+1
            if ans < a[i][j]+1:
                ans=a[i][j]+1
        if i<h-1 and a[i+1][j]==".":
            que.append([i+1,j])
            a[i+1][j]=a[i][j]+1
            if ans < a[i][j]+1:
                ans=a[i][j]+1
        if 0<i and a[i-1][j]==".":
            que.append([i-1,j])
            a[i-1][j]=a[i][j]+1
            if ans < a[i][j]+1:
                ans=a[i][j]+1
    print(ans)
if __name__ == "__main__":
    main()

Fixed submission:
def main():
    h,w = map(int,input().split())
    a=[]
    que=[]
    for _ in range(h):
        a.append(list(input()))
    for i in range(h):
        for j in range(w):
            if a[i][j]=="#":
                que.append([i,j])
                a[i][j]=0
    ans=0
    while que!=[]:
        tank=[]
        for i,j in que:
            if j<w-1 and a[i][j+1]==".":
                tank.append([i,j+1])
                a[i][j+1]=a[i][j]+1
            if 0<j and a[i][j-1]==".":
                tank.append([i,j-1])
                a[i][j-1]=a[i][j]+1
            if i<h-1 and a[i+1][j]==".":
                tank.append([i+1,j])
                a[i+1][j]=a[i][j]+1
            if 0<i and a[i-1][j]==".":
                tank.append([i-1,j])
                a[i-1][j]=a[i][j]+1
        que=tank
        ans+=1
    print(ans-1)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    h,w = map(int,input().split()) 
    x=[[-1 for _ in range(w)] for _ in range(h)]
    a=[]
    que=[]
    for _ in range(h):
        a.append(list(input()))
    for i in range(h):
        for j in range(w):
            if a[i][j]=="#":
                que.append([i,j])
                x[i][j]=0
    ans=0
    while que!=[]:
        [i,j]=que[0]
        que.pop(0)
        if j<w-1 and x[i][j+1]==-1:
            que.append([i,j+1])
            x[i][j+1]=x[i][j]+1
            if ans < x[i][j]+1:
                ans=x[i][j]+1
        if 0<j and x[i][j-1]==-1:
            que.append([i,j-1])
            x[i][j-1]=x[i][j]+1
            if ans < x[i][j]+1:
                ans=x[i][j]+1
        if i<h-1 and x[i+1][j]==-1:
            que.append([i+1,j])
            x[i+1][j]=x[i][j]+1
            if ans < x[i][j]+1:
                ans=x[i][j]+1
        if 0<i and x[i-1][j]==-1:
            que.append([i-1,j])
            x[i-1][j]=x[i][j]+1
            if ans < x[i][j]+1:
                ans=x[i][j]+1
    print(ans)
if __name__ == "__main__":
    main()

Fixed submission:
def main():
    h,w = map(int,input().split())
    a=[]
    que=[]
    for _ in range(h):
        a.append(list(input()))
    for i in range(h):
        for j in range(w):
            if a[i][j]=="#":
                que.append([i,j])
                a[i][j]=0
    ans=0
    while que!=[]:
        tank=[]
        for i,j in que:
            if j<w-1 and a[i][j+1]==".":
                tank.append([i,j+1])
                a[i][j+1]=a[i][j]+1
            if 0<j and a[i][j-1]==".":
                tank.append([i,j-1])
                a[i][j-1]=a[i][j]+1
            if i<h-1 and a[i+1][j]==".":
                tank.append([i+1,j])
                a[i+1][j]=a[i][j]+1
            if 0<i and a[i-1][j]==".":
                tank.append([i-1,j])
                a[i-1][j]=a[i][j]+1
        que=tank
        ans+=1
    print(ans-1)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    h,w = map(int,input().split()) 
    x=[[-1 for _ in range(w)] for _ in range(h)]
    a=[]
    for _ in range(h):
        a.append(list(input()))
    for i in range(h):
        for j in range(w):
            if a[i][j]=="#":
                x[i][j]=0
    cnt=0
    check=0
    while True:
        key=0
        for i in range(h):
            for j in range(w):
                if x[i][j]==-1:
                    key=1
                    if j<w-1 and x[i][j+1]==check:
                        x[i][j]=x[i][j+1]+1
                    elif 0<j and x[i][j-1]==check:
                        x[i][j]=x[i][j-1]+1
                    elif i<h-1 and x[i+1][j]==check:
                        x[i][j]=x[i+1][j]+1
                    elif 0<i and x[i-1][j]==check:
                        x[i][j]=x[i-1][j]+1
        if key==0:
            break
        else:
            check+=1
            cnt+=1
    print(cnt)
if __name__ == "__main__":
    main()

Fixed submission:
def main():
    h,w = map(int,input().split())
    a=[]
    que=[]
    for _ in range(h):
        a.append(list(input()))
    for i in range(h):
        for j in range(w):
            if a[i][j]=="#":
                que.append([i,j])
                a[i][j]=0
    ans=0
    while que!=[]:
        tank=[]
        for i,j in que:
            if j<w-1 and a[i][j+1]==".":
                tank.append([i,j+1])
                a[i][j+1]=a[i][j]+1
            if 0<j and a[i][j-1]==".":
                tank.append([i,j-1])
                a[i][j-1]=a[i][j]+1
            if i<h-1 and a[i+1][j]==".":
                tank.append([i+1,j])
                a[i+1][j]=a[i][j]+1
            if 0<i and a[i-1][j]==".":
                tank.append([i-1,j])
                a[i-1][j]=a[i][j]+1
        que=tank
        ans+=1
    print(ans-1)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    h,w = map(int,input().split()) 
    x=[[0 for _ in range(w)] for _ in range(h)]
    a=[]
    for _ in range(h):
        a.append(list(input()))
    for i in range(h):
        for j in range(w):
            if a[i][j]=="#":
                x[i][j]=1
    cnt=0
    while True:
        key=0
        b=[]
        for i in range(h):
            for j in range(w):
                key1=0
                if x[i][j]==0:
                    key=1
                    if j<w-1 and a[i][j+1]=="#":
                        x[i][j]=1
                        key1=1
                    elif 0<j and a[i][j-1]=="#":
                        x[i][j]=1
                        key1=1
                    elif i<h-1 and a[i+1][j]=="#":
                        x[i][j]=1
                        key1=1
                    elif 0<i and a[i-1][j]=="#":
                        x[i][j]=1
                        key1=1
                if key1==1:
                    b.append([i,j])
        while b!=[]:
            [n,m]=b[0]
            a[n][m]="#"
            b.pop(0)
        if key==0:
            break
        else:
            cnt+=1
    print(cnt)


if __name__ == "__main__":
    main()

Fixed submission:
def main():
    h,w = map(int,input().split())
    a=[]
    que=[]
    for _ in range(h):
        a.append(list(input()))
    for i in range(h):
        for j in range(w):
            if a[i][j]=="#":
                que.append([i,j])
                a[i][j]=0
    ans=0
    while que!=[]:
        tank=[]
        for i,j in que:
            if j<w-1 and a[i][j+1]==".":
                tank.append([i,j+1])
                a[i][j+1]=a[i][j]+1
            if 0<j and a[i][j-1]==".":
                tank.append([i,j-1])
                a[i][j-1]=a[i][j]+1
            if i<h-1 and a[i+1][j]==".":
                tank.append([i+1,j])
                a[i+1][j]=a[i][j]+1
            if 0<i and a[i-1][j]==".":
                tank.append([i-1,j])
                a[i-1][j]=a[i][j]+1
        que=tank
        ans+=1
    print(ans-1)
if __name__ == "__main__":
    main()