Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
H,W=map(int,input().split())
A=[]
for i in range(H):
    a=list(input())
    A.append(a)
#多点スタートな最短路問題
q=deque()
dist=[[-1 for _ in range(W)]for i in range(H)]

for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            dist[i][j]=0
            q.append([i,j])

dx=[1,0,-1,0]
dy=[0,1,0,-1]
while(len(q)):
    h,w=q.popleft()
    #print(h,w)
    #print(q)
    for i in range(4):
        y=h+dy[i]
        x=w+dx[i]
        if (y<0)or(y>=H)or(x<0)or(x>=W):
            continue
        if dist[y][x]==-1:
            dist[y][x]=dist[h][w]+1
            q.append([y,x])
ans=0
#print(dist)
for i in range(len(dist)):
    ans=max(ans,max(dist[i]))
print(ans)

Fixed submission:
from collections import deque
import sys
H,W=map(int,input().split())
A=[]
for i in range(H):
    a=list(input())
    A.append(a)
#多点スタートな最短路問題
q=deque()
dist=[[-1 for _ in range(W)]for i in range(H)]

for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            dist[i][j]=0
            q.append([i,j])

dx=[1,0,-1,0]
dy=[0,1,0,-1]
while(len(q)):
    h,w=q.popleft()
    #print(h,w)
    #print(q)
    for i in range(4):
        y=h+dy[i]
        x=w+dx[i]
        if (y<0)or(y>=H)or(x<0)or(x>=W):
            continue
        if dist[y][x]==-1:
            dist[y][x]=dist[h][w]+1
            q.append([y,x])
ans=0
#print(dist)
for i in range(len(dist)):
    ans=max(ans,max(dist[i]))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
H,W=map(int,input().split())
A=[]
for i in range(H):
    a=list(input())
    A.append(a)
#多点スタートな最短路問題
q=deque()
dist=[[-1 for _ in range(W)]for i in range(H)]

for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            dist[i][j]=0
            q.append([i,j])

dx=[1,0,-1,0]
dy=[0,1,0,-1]
while(len(q)):
    h,w=q.popleft()
    #print(h,w)
    #print(q)
    for i in range(4):
        y=h+dy[i]
        x=w+dx[i]
        if (y<0)or(y>=H)or(x<0)or(x>=W):
            continue
        if dist[y][x]==-1:
            dist[y][x]=dist[h][w]+1
            q.append([y,x])
ans=0
#print(dist)
for i in range(H):
    for j in range(W):
        ans=max(ans,dist[i][j])
print(ans)

Fixed submission:
from collections import deque
import sys
H,W=map(int,input().split())
A=[]
for i in range(H):
    a=list(input())
    A.append(a)
#多点スタートな最短路問題
q=deque()
dist=[[-1 for _ in range(W)]for i in range(H)]

for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            dist[i][j]=0
            q.append([i,j])

dx=[1,0,-1,0]
dy=[0,1,0,-1]
while(len(q)):
    h,w=q.popleft()
    #print(h,w)
    #print(q)
    for i in range(4):
        y=h+dy[i]
        x=w+dx[i]
        if (y<0)or(y>=H)or(x<0)or(x>=W):
            continue
        if dist[y][x]==-1:
            dist[y][x]=dist[h][w]+1
            q.append([y,x])
ans=0
#print(dist)
for i in range(len(dist)):
    ans=max(ans,max(dist[i]))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())
A=[]
for i in range(H):
    a=list(input())
    A.append(a)

w=[]
cnt=[[10**7 for _ in range(W)]for i in range(H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            for y,x in w:
                val=abs(y-i)+abs(x-j)
                cnt[y][x]=min(cnt[y][x],val)
            w=[]
        else:
            w.append([i,j])
w=[]
for i in range(H):
    for j in range(W):
        y=i
        if i%2==0:
            x=j
        else:
            x=W-1-j
        if A[y][x]=="#":
            for n,m in w:
                val=abs(n-y)+abs(m-x)
                cnt[n][m]=min(cnt[n][m],val)
            w=[]
        else:
            w.append([y,x])
w=[]
for i in range(H):
    for j in range(W):
        y=i
        x=W-1-j
        if A[y][x]=="#":
            for n,m in w:
                val=abs(n-y)+abs(m-x)
                cnt[n][m]=min(cnt[n][m],val)
            w=[]
        else:
            w.append([y,x])

for i in range(H):
    for j in range(W):
        y=i
        if i%2==0:
            x=W-1-j
        else:
            x=j
        if A[y][x]=="#":
            for n,m in w:
                val=abs(n-y)+abs(m-x)
                cnt[n][m]=min(cnt[n][m],val)
            w=[]
        else:
            w.append([y,x])

for j in range(W):
    for i in range(H):
        y=i
        x=j
        if A[y][x]=="#":
            for n,m in w:
                val=abs(n-y)+abs(m-x)
                cnt[n][m]=min(cnt[n][m],val)
            w=[]
        else:
            w.append([y,x])
for j in range(W):
    for i in range(H):
        if j%2==0:
            y=i
        else:
            y=H-1-i
        x=j
        if A[y][x]=="#":
            for n,m in w:
                val=abs(n-y)+abs(m-x)
                cnt[n][m]=min(cnt[n][m],val)
            w=[]
        else:
            w.append([y,x])
for j in range(W):
    for i in range(H):
        y=H-1-i
        x=j
        if A[y][x]=="#":
            for n,m in w:
                val=abs(n-y)+abs(m-x)
                cnt[n][m]=min(cnt[n][m],val)
            w=[]
        else:
            w.append([y,x])
for j in range(W):
    for i in range(H):
        if j%2==0:
            y=H-1-i
        else:
            y=i
        x=j
        if A[y][x]=="#":
            for n,m in w:
                val=abs(n-y)+abs(m-x)
                cnt[n][m]=min(cnt[n][m],val)
            w=[]
        else:
            w.append([y,x])
ans=0
for i in range(H):
    for j in range(W):
        if A[i][j]==".":
            ans=max(ans,cnt[i][j])

print(ans)

Fixed submission:
from collections import deque
import sys
H,W=map(int,input().split())
A=[]
for i in range(H):
    a=list(input())
    A.append(a)
#多点スタートな最短路問題
q=deque()
dist=[[-1 for _ in range(W)]for i in range(H)]

for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            dist[i][j]=0
            q.append([i,j])

dx=[1,0,-1,0]
dy=[0,1,0,-1]
while(len(q)):
    h,w=q.popleft()
    #print(h,w)
    #print(q)
    for i in range(4):
        y=h+dy[i]
        x=w+dx[i]
        if (y<0)or(y>=H)or(x<0)or(x>=W):
            continue
        if dist[y][x]==-1:
            dist[y][x]=dist[h][w]+1
            q.append([y,x])
ans=0
#print(dist)
for i in range(len(dist)):
    ans=max(ans,max(dist[i]))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())
A=[]
for i in range(H):
    a=list(input())
    A.append(a)

white=[]
black=[]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            cnt=0
            if (i+1)<H:
                if A[i+1][j]=="#":
                    cnt+=1
            if (i-1)>=0:
                if A[i-1][j]=="#":
                    cnt+=1
            if (j+1)<W:
                if A[i][j+1]=="#":
                    cnt+=1
            if (j-1)>=0:
                if A[i][j-1]=="#":
                    cnt+=1
            if cnt==4:
                pass
            else:
                black.append([i,j])
        else:
            white.append([i,j])
ans=0
for h,w in white:
    val=10**10
    for i,j in black:
        val1=abs(h-i)+abs(w-j)
        val=min(val,val1)
    ans=max(ans,val)

print(ans)

Fixed submission:
from collections import deque
import sys
H,W=map(int,input().split())
A=[]
for i in range(H):
    a=list(input())
    A.append(a)
#多点スタートな最短路問題
q=deque()
dist=[[-1 for _ in range(W)]for i in range(H)]

for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            dist[i][j]=0
            q.append([i,j])

dx=[1,0,-1,0]
dy=[0,1,0,-1]
while(len(q)):
    h,w=q.popleft()
    #print(h,w)
    #print(q)
    for i in range(4):
        y=h+dy[i]
        x=w+dx[i]
        if (y<0)or(y>=H)or(x<0)or(x>=W):
            continue
        if dist[y][x]==-1:
            dist[y][x]=dist[h][w]+1
            q.append([y,x])
ans=0
#print(dist)
for i in range(len(dist)):
    ans=max(ans,max(dist[i]))
print(ans)