Buggy python submission (verdict: Time Limit Exceeded):
def BFS(y,x):
    z= [[False for _ in range(W)] for _ in range(H)]
    v=deque( [[y,x]] )
    d[y][x]=0
    z[y][x]=True
    
    while v:
        a=v.popleft()
        for mv in move:
            s=a[0]+mv[0]
            t=a[1]+mv[1]
            if 0<=s<H and 0<=t<W:
                if z[s][t]==False:
                    z[s][t]=True
                    d[s][t]=min(d[s][t], d[a[0]][a[1]]+1)
                    v.append([s,t])
                    
    
from collections import deque
H,W=map(int,input().split())
A= [list(input()) for _ in range(H)]
d= [[2000 for _ in range(W)] for _ in range(H)]
move= [ (0,1),(0,-1),(1,0),(-1,0) ]


for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
                BFS(i,j)
                
#print(d)
maxi=0
for i in d:
    for j in i:
        maxi=max(maxi,j)
print(maxi)

Fixed submission:
from collections import deque
H,W=map(int,input().split())
A= [list(input()) for _ in range(H)]
d= [[2000 for _ in range(W)] for _ in range(H)]
move= [ (0,1),(0,-1),(1,0),(-1,0) ]
z= [[False for _ in range(W)] for _ in range(H)]
ans=0

v=deque([])
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            v.append( [i,j] )
            z[i][j]=True
            d[i][j]=0
while v:
    a=v.popleft()
    #print(a,v)
    for mv in move:
        s=a[0]+mv[0]
        t=a[1]+mv[1]
        if 0<=s<H and 0<=t<W:
            if z[s][t]==False:
                z[s][t]=True
                d[s][t]=d[a[0]][a[1]]+1
                v.append([s,t])
                ans=max(ans,d[s][t])
#print(d)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def BFS(y,x):
    z= [[False for _ in range(W)] for _ in range(H)]
    v=deque( [[y,x]] )
    d[y][x]=0
    z[y][x]=True
    
    while v:
        a=v.popleft()
        for mv in move:
            s=a[0]+mv[0]
            t=a[1]+mv[1]
            if 0<=s<H and 0<=t<W:
                if z[s][t]==False:
                    z[s][t]=True
                    d[s][t]=min(d[s][t], d[a[0]][a[1]]+1)
                    v.append([s,t])
                    
    
from collections import deque
H,W=map(int,input().split())
A= [list(input()) for _ in range(H)]
d= [[2000 for _ in range(W)] for _ in range(H)]
move= [ (0,1),(0,-1),(1,0),(-1,0) ]


for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
                BFS(i,j)
                
#print(d)
maxi=0
for i in d:
    for j in i:
        maxi=max(maxi,j)
print(maxi)

Fixed submission:
from collections import deque
H,W=map(int,input().split())
A= [list(input()) for _ in range(H)]
d= [[2000 for _ in range(W)] for _ in range(H)]
move= [ (0,1),(0,-1),(1,0),(-1,0) ]
z= [[False for _ in range(W)] for _ in range(H)]
ans=0

v=deque([])
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            v.append( [i,j] )
            z[i][j]=True
            d[i][j]=0
while v:
    a=v.popleft()
    #print(a,v)
    for mv in move:
        s=a[0]+mv[0]
        t=a[1]+mv[1]
        if 0<=s<H and 0<=t<W:
            if z[s][t]==False:
                z[s][t]=True
                d[s][t]=d[a[0]][a[1]]+1
                v.append([s,t])
                ans=max(ans,d[s][t])
#print(d)
print(ans)

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

def paint_center(a,b):
  paint_point(a-1,b)
  paint_point(a+1,b)
  paint_point(a,b-1)
  paint_point(a,b+1)

def paint_point(a,b):
  if 0<=a and a<H:
    if 0<=b and b<W:
      A[a][b]="#"

#黒いマスを探してその周りを黒く塗る


count=0
flag=False #白があればTrue
end_flag=False

while end_flag==False:
  #全マスが黒かどうかのチェック
  flag=False
  black_list=[[]]
  del black_list[0]
  
  for i in range(0,H):
    for j in range(0,W):
      if A[i][j]==".":
        flag=True
        #break
      else:
        #pass
        black_list.append([i,j])
        
  if flag==True:
    #for i in range(0,H):
    #  for j in range(0,W):
    #    if A[i][j]=="#":
    #      black_list.append([i,j])
    #print(black_list)
    for i,j in black_list:
      paint_center(i,j)
    count=count+1
    
  else:
    end_flag=True
    print(count)
    break

Fixed submission:
from collections import deque
H,W=map(int,input().split())
A= [list(input()) for _ in range(H)]
d= [[2000 for _ in range(W)] for _ in range(H)]
move= [ (0,1),(0,-1),(1,0),(-1,0) ]
z= [[False for _ in range(W)] for _ in range(H)]
ans=0

v=deque([])
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            v.append( [i,j] )
            z[i][j]=True
            d[i][j]=0
while v:
    a=v.popleft()
    #print(a,v)
    for mv in move:
        s=a[0]+mv[0]
        t=a[1]+mv[1]
        if 0<=s<H and 0<=t<W:
            if z[s][t]==False:
                z[s][t]=True
                d[s][t]=d[a[0]][a[1]]+1
                v.append([s,t])
                ans=max(ans,d[s][t])
#print(d)
print(ans)

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

black_list=[[]]
del black_list[0]

def paint_center(a,b):
  paint_point(a-1,b)
  paint_point(a+1,b)
  paint_point(a,b-1)
  paint_point(a,b+1)

def paint_point(a,b):
  if 0<=a and a<H:
    if 0<=b and b<W:
      A[a][b]="#"

#黒いマスを探してその周りを黒く塗る


count=0
flag=False #白があればTrue
end_flag=False

while end_flag==False:
  #全マスが黒かどうかのチェック
  flag=False

  for i in range(0,H):
    for j in range(0,W):
      if A[i][j]==".":
        flag=True
      else:
        pass

  
  if flag==True:
    for i in range(0,H):
      for j in range(0,W):
        if A[i][j]=="#":
          black_list.append([i,j])
    for i,j in black_list:
      paint_center(i,j)
    count=count+1
    
  else:
    print(count)
    break

Fixed submission:
from collections import deque
H,W=map(int,input().split())
A= [list(input()) for _ in range(H)]
d= [[2000 for _ in range(W)] for _ in range(H)]
move= [ (0,1),(0,-1),(1,0),(-1,0) ]
z= [[False for _ in range(W)] for _ in range(H)]
ans=0

v=deque([])
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            v.append( [i,j] )
            z[i][j]=True
            d[i][j]=0
while v:
    a=v.popleft()
    #print(a,v)
    for mv in move:
        s=a[0]+mv[0]
        t=a[1]+mv[1]
        if 0<=s<H and 0<=t<W:
            if z[s][t]==False:
                z[s][t]=True
                d[s][t]=d[a[0]][a[1]]+1
                v.append([s,t])
                ans=max(ans,d[s][t])
#print(d)
print(ans)