Buggy python submission (verdict: Time Limit Exceeded):
import queue

h,w=list(map(int,input().split()))
a=[input() for _ in range(h)]
#a[h][w]
direction=[[-1,0],[1,0],[0,-1],[0,1]]
visited=[[-1]*w for _ in range(h)]
q=queue.Queue()

#全ての黒マスをキューに入れる
for hi in range(h):
  for wi in range(w):
    if a[hi][wi]=="#":
      q.put([hi,wi])
      visited[hi][wi]=0

while not q.empty():
  ch,cw=q.get()
  for d in direction:
    nh=ch+d[0]
    nw=cw+d[1]
    #端からはみでない、まだ見てない白マス
    if nh>=0 and nw>=0 and nh<h and nw<w and visited[nh][nw]==-1:
      q.put([nh,nw])
      visited[nh][nw]=visited[ch][cw]+1

ans=0
for hi in range(h):
  tmp=max(visited[hi])
  if tmp > ans:
    ans=tmp
print(ans)


Fixed submission:
import collections

h,w=list(map(int,input().split()))
a=[input() for _ in range(h)]
#a[h][w]
direction=[[-1,0],[1,0],[0,-1],[0,1]]
visited=[[-1]*w for _ in range(h)]
q=collections.deque()

#全ての黒マスをキューに入れる
for hi in range(h):
  for wi in range(w):
    if a[hi][wi]=="#":
      q.append([hi,wi])
      visited[hi][wi]=0

while len(q)>0:
  ch,cw=q.popleft()
  for d in direction:
    nh=ch+d[0]
    nw=cw+d[1]
    #端からはみでない、まだ見てない白マス
    if nh>=0 and nw>=0 and nh<h and nw<w and visited[nh][nw]==-1:
      q.append([nh,nw])
      visited[nh][nw]=visited[ch][cw]+1

ans=0
for hi in range(h):
  tmp=max(visited[hi])
  if tmp > ans:
    ans=tmp
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import queue

h,w=list(map(int,input().split()))
a=[input() for _ in range(h)]
#a[h][w]
direction=[[-1,0],[1,0],[0,-1],[0,1]]
visited=[[-1]*w for _ in range(h)]
q=queue.Queue()

#全ての黒マスをキューに入れる
for hi in range(h):
  for wi in range(w):
    if a[hi][wi]=="#":
      q.put([hi,wi])
      visited[hi][wi]=0

while not q.empty():
  ch,cw=q.get()
  for d in direction:
    nh=ch+d[0]
    nw=cw+d[1]
    #端からはみでない、まだ見てない白マス
    if nh>=0 and nw>=0 and nh<h and nw<w and visited[nh][nw]==-1:
      q.put([nh,nw])
      visited[nh][nw]=visited[ch][cw]+1

ans=0
for hi in range(h):
  tmp=max(visited[hi])
  if tmp > ans:
    ans=tmp
print(ans)


Fixed submission:
import collections

h,w=list(map(int,input().split()))
a=[input() for _ in range(h)]
#a[h][w]
direction=[[-1,0],[1,0],[0,-1],[0,1]]
visited=[[-1]*w for _ in range(h)]
q=collections.deque()

#全ての黒マスをキューに入れる
for hi in range(h):
  for wi in range(w):
    if a[hi][wi]=="#":
      q.append([hi,wi])
      visited[hi][wi]=0

while len(q)>0:
  ch,cw=q.popleft()
  for d in direction:
    nh=ch+d[0]
    nw=cw+d[1]
    #端からはみでない、まだ見てない白マス
    if nh>=0 and nw>=0 and nh<h and nw<w and visited[nh][nw]==-1:
      q.append([nh,nw])
      visited[nh][nw]=visited[ch][cw]+1

ans=0
for hi in range(h):
  tmp=max(visited[hi])
  if tmp > ans:
    ans=tmp
print(ans)

Buggy python submission (verdict: Runtime Error):
import queue
h,w=list(map(int,input().split()))
a=[]
for i in range(h):
  a.append(input())

#a[たて][よこ]
ma=0
li=[[0]*w for _ in range(h)]
li2=[[True]*w for _ in range(h)]
#そのマスが何手目で黒くなるかを調べる
#隣に黒がなければ、上下左右の一番小さいserch+1
#隣に黒があれば、1
def search(i,j):
  li2[i][j]= False
  if li[i][j]!= 0:
    return li[i][j]
  u=9999
  d=9999
  r=9999
  l=9999
  if i-1>=0:
    if a[i-1][j]=="#":
      li[i][j]=1
      return 1
    elif li2[i-1][j]:
      u=search(i-1,j)
  if i+1<h:
    if a[i+1][j]=="#":
      li[i][j]=1
      return 1
    elif li2[i+1][j]:
      d=search(i+1,j)
  if j-1>=0:
    if a[i][j-1]=="#":
      li[i][j]=1
      return 1
    elif li2[i][j-1]:
      l=search(i,j-1)
  if j+1<w:
    if a[i][j+1]=="#":
      li[i][j]=1
      return 1
    elif li2[i][j+1]:
      r=search(i,j+1)
  li[i][j]=min(u,d,r,l)+1
  return min(u,d,r,l)+1

ans=0
for hi in range(h):
  for wi in range(w):
    if a[hi][wi]==".":
      li2=[[True]*w for _ in range(h)]
      tmp= search(hi,wi)
      if tmp>ans:
        ans=tmp
print(ans)

Fixed submission:
import collections

h,w=list(map(int,input().split()))
a=[input() for _ in range(h)]
#a[h][w]
direction=[[-1,0],[1,0],[0,-1],[0,1]]
visited=[[-1]*w for _ in range(h)]
q=collections.deque()

#全ての黒マスをキューに入れる
for hi in range(h):
  for wi in range(w):
    if a[hi][wi]=="#":
      q.append([hi,wi])
      visited[hi][wi]=0

while len(q)>0:
  ch,cw=q.popleft()
  for d in direction:
    nh=ch+d[0]
    nw=cw+d[1]
    #端からはみでない、まだ見てない白マス
    if nh>=0 and nw>=0 and nh<h and nw<w and visited[nh][nw]==-1:
      q.append([nh,nw])
      visited[nh][nw]=visited[ch][cw]+1

ans=0
for hi in range(h):
  tmp=max(visited[hi])
  if tmp > ans:
    ans=tmp
print(ans)