Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H,W = map(int,input().split())

by,bx= deque(),deque()
Map = []
Map.append('@'*(W+2))
for i in range(H):
  c = list('@'+input()+'@')
  Map.append(c)
  for j in range(W+2):
    if(c[j] == '#'):
      Map[i+1][j] = 0
      by.append(i+1),bx.append(j)
Map.append('@'*(W+2))      

cnt = 0
while(1):
  if(len(by) == 0):
    cnt = Map[ny][nx]
    break
   
  ny,nx = by.popleft(),bx.popleft()
  vec_y,vec_x = [1,-1,0,0],[0,0,1,-1]
  for i in range(4):
      if(Map[ny+vec_y[i]][nx+vec_x[i]] == '.'):
         Map[ny+vec_y[i]][nx+vec_x[i]] = Map[ny][nx] + 1
         by.append(ny+vec_y[i]),bx.append(nx+vec_x[i])
  
print(cnt)  

Fixed submission:
from collections import deque

H,W = map(int,input().split())

by,bx= deque(),deque()
Map = []
Map.append('@'*(W+2))
for i in range(H):
  c = list('@'+input()+'@')
  Map.append(c)
  for j in range(W+2):
    if(c[j] == '#'):
      Map[i+1][j] = 0
      by.append(i+1),bx.append(j)
Map.append('@'*(W+2))      

cnt = 0
while(1):
  if(len(by) == 0):
    break
   
  ny,nx = by.popleft(),bx.popleft()
  vec_y,vec_x = [1,-1,0,0],[0,0,1,-1]
  for i in range(4):
      if(Map[ny+vec_y[i]][nx+vec_x[i]] == '.'):
         Map[ny+vec_y[i]][nx+vec_x[i]] = Map[ny][nx] + 1
         cnt = max(cnt, Map[ny][nx] + 1) 
         by.append(ny+vec_y[i]),bx.append(nx+vec_x[i])
  
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H,W = map(int,input().split())

by,bx= deque(),deque()
Map = []
Map.append('@'*(W+2))
for i in range(H):
  c = list('@'+input()+'@')
  Map.append(c)
  for j in range(W+2):
    if(c[j] == '#'):
      Map[i+1][j] = 0
      by.append(i+1),bx.append(j)
Map.append('@'*(W+2))      

cnt = 0
while(1):
  if(len(by) == 0):
    break
   
  ny,nx = by.popleft(),bx.popleft()
  vec_y,vec_x = [1,-1,0,0],[0,0,1,-1]
  for i in range(4):
      if(Map[ny+vec_y[i]][nx+vec_x[i]] == '.'):
         Map[ny+vec_y[i]][nx+vec_x[i]] = Map[ny][nx] + 1
         cnt = max(cnt, Map[ny][nx] + 1) 
         by.append(ny+vec_y[i]),bx.append(nx+vec_x[i])
  
print(cnt)  

Fixed submission:
from collections import deque

H,W = map(int,input().split())

by,bx= deque(),deque()
Map = []
Map.append('@'*(W+2))
for i in range(H):
  c = list('@'+input()+'@')
  Map.append(c)
  for j in range(W+2):
    if(c[j] == '#'):
      Map[i+1][j] = 0
      by.append(i+1),bx.append(j)
Map.append('@'*(W+2))      

cnt = 0
while(1):
  if(len(by) == 0):
    break
   
  ny,nx = by.popleft(),bx.popleft()
  vec_y,vec_x = [1,-1,0,0],[0,0,1,-1]
  for i in range(4):
      if(Map[ny+vec_y[i]][nx+vec_x[i]] == '.'):
         Map[ny+vec_y[i]][nx+vec_x[i]] = Map[ny][nx] + 1
         cnt = max(cnt, Map[ny][nx] + 1) 
         by.append(ny+vec_y[i]),bx.append(nx+vec_x[i])
  
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
#(方針)「whiteから最も近いblackまでの距離」の最大値を求める
import queue
import copy
#sys.stdin.readline()
import sys
input = sys.stdin.readline

H,W = map(int,input().split())
white_index = []
Map = []
Map.append(['@']*(W+2))
for i in range(H):
  c = list('@'+input()+'@')
  Map.append(c)
  for j in range(W+2):
    if(c[j] == '.'): white_index.append([i+1,j])
Map.append(['@']*(W+2))


#幅優先探索
def bfs(sy,sx,Map):
  Map_[sy][sx] = 0
  qy,qx = queue.Queue(),queue.Queue()
  qy.put(sy),qx.put(sx)
  
  count = 0
  while(1):
   if(qx.empty() == True): return ans
    
   #座標の取り出し
   y,x = qy.get(),qx.get()
   if(Map_[y][x] == '#'): #ゴールなら終了
    return count

   #if((sy == 4)and(sx == 6)):
    #for i in range(H+2): print(Map_[i])
    #print('_____________')
    
   #次に進むところ
   vec_y = [0,0,1,-1]
   vec_x = [1,-1,0,0]
   for i in range(4):
     if(Map_[y+vec_y[i]][x+vec_x[i]] == '.'):
      Map_[y+vec_y[i]][x+vec_x[i]] = Map_[y][x] + 1
      qy.put(y+vec_y[i]),qx.put(x+vec_x[i])
     elif(Map_[y+vec_y[i]][x+vec_x[i]] == '#'): #ゴールなら終了
      count = Map_[y][x] + 1
      return count      
     

ans = 0
for i in range(len(white_index)):
 sy,sx = white_index[i][0],white_index[i][1]
 Map_ = copy.deepcopy(Map) #二次元リストのコピー
 ans = max(ans,bfs(sy,sx,Map_))  
print(ans)

Fixed submission:
from collections import deque

H,W = map(int,input().split())

by,bx= deque(),deque()
Map = []
Map.append('@'*(W+2))
for i in range(H):
  c = list('@'+input()+'@')
  Map.append(c)
  for j in range(W+2):
    if(c[j] == '#'):
      Map[i+1][j] = 0
      by.append(i+1),bx.append(j)
Map.append('@'*(W+2))      

cnt = 0
while(1):
  if(len(by) == 0):
    break
   
  ny,nx = by.popleft(),bx.popleft()
  vec_y,vec_x = [1,-1,0,0],[0,0,1,-1]
  for i in range(4):
      if(Map[ny+vec_y[i]][nx+vec_x[i]] == '.'):
         Map[ny+vec_y[i]][nx+vec_x[i]] = Map[ny][nx] + 1
         cnt = max(cnt, Map[ny][nx] + 1) 
         by.append(ny+vec_y[i]),bx.append(nx+vec_x[i])
  
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
#(方針)「whiteから最も近いblackまでの距離」の最大値を求める
import queue
import copy

H,W = map(int,input().split())
white_index = []
Map = []
Map.append(['@']*(W+2))
for i in range(H):
  c = list('@'+input()+'@')
  Map.append(c)
  for j in range(W+2):
    if(c[j] == '.'): white_index.append([i+1,j])
Map.append(['@']*(W+2))


#幅優先探索
def bfs(sy,sx,Map):
  Map_[sy][sx] = 0
  qy,qx = queue.Queue(),queue.Queue()
  qy.put(sy),qx.put(sx)
  
  count = 0
  while(1):
   if(qx.empty() == True): return ans
    
   #座標の取り出し
   y,x = qy.get(),qx.get()
   if(Map_[y][x] == '#'): #ゴールなら終了
    return count

   #if((sy == 4)and(sx == 6)):
    #for i in range(H+2): print(Map_[i])
    #print('_____________')
    
   #次に進むところ
   vec_y = [0,0,1,-1]
   vec_x = [1,-1,0,0]
   for i in range(4):
     if(Map_[y+vec_y[i]][x+vec_x[i]] == '.'):
      Map_[y+vec_y[i]][x+vec_x[i]] = Map_[y][x] + 1
      qy.put(y+vec_y[i]),qx.put(x+vec_x[i])
     elif(Map_[y+vec_y[i]][x+vec_x[i]] == '#'): #ゴールなら終了
      count = Map_[y][x] + 1
      return count      
     

ans = 0
for i in range(len(white_index)):
 sy,sx = white_index[i][0],white_index[i][1]
 Map_ = copy.deepcopy(Map) #二次元リストのコピー
 ans = max(ans,bfs(sy,sx,Map_))  
print(ans)

Fixed submission:
from collections import deque

H,W = map(int,input().split())

by,bx= deque(),deque()
Map = []
Map.append('@'*(W+2))
for i in range(H):
  c = list('@'+input()+'@')
  Map.append(c)
  for j in range(W+2):
    if(c[j] == '#'):
      Map[i+1][j] = 0
      by.append(i+1),bx.append(j)
Map.append('@'*(W+2))      

cnt = 0
while(1):
  if(len(by) == 0):
    break
   
  ny,nx = by.popleft(),bx.popleft()
  vec_y,vec_x = [1,-1,0,0],[0,0,1,-1]
  for i in range(4):
      if(Map[ny+vec_y[i]][nx+vec_x[i]] == '.'):
         Map[ny+vec_y[i]][nx+vec_x[i]] = Map[ny][nx] + 1
         cnt = max(cnt, Map[ny][nx] + 1) 
         by.append(ny+vec_y[i]),bx.append(nx+vec_x[i])
  
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int,input().split())

A = []
A.append(list('@'*(W+2)))
for i in range(H):
  a = list('@'+input()+'@')
  A.append(a)
A.append(list('@'*(W+2)))

b_count = 0
b_list,w_list = [],[]
for i in range(H+2):
 if((i != 0)and(i != H+1)):
  for j in range(W+2):
   if((j != 0)and(j != W+1)):
    if(A[i][j] == '#'):  b_list.append([i,j])
    elif(A[i][j] == '.'): w_list.append([i,j])

ans = 0
for i in range(len(w_list)):
 tmp_min = float('inf')
 w_y,w_x = w_list[i][0],w_list[i][1]
 for j in range(len(b_list)):
  b_y,b_x = b_list[j][0],b_list[j][1]
  tmp = abs(w_y-b_y)+abs(w_x-b_x)
  tmp_min = min(tmp_min,tmp)
 ans = max(ans,tmp_min)
 
print(ans)      
  

Fixed submission:
from collections import deque

H,W = map(int,input().split())

by,bx= deque(),deque()
Map = []
Map.append('@'*(W+2))
for i in range(H):
  c = list('@'+input()+'@')
  Map.append(c)
  for j in range(W+2):
    if(c[j] == '#'):
      Map[i+1][j] = 0
      by.append(i+1),bx.append(j)
Map.append('@'*(W+2))      

cnt = 0
while(1):
  if(len(by) == 0):
    break
   
  ny,nx = by.popleft(),bx.popleft()
  vec_y,vec_x = [1,-1,0,0],[0,0,1,-1]
  for i in range(4):
      if(Map[ny+vec_y[i]][nx+vec_x[i]] == '.'):
         Map[ny+vec_y[i]][nx+vec_x[i]] = Map[ny][nx] + 1
         cnt = max(cnt, Map[ny][nx] + 1) 
         by.append(ny+vec_y[i]),bx.append(nx+vec_x[i])
  
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int,input().split())

A = []
A.append(list('@'*(W+2)))
for i in range(H):
  a = list('@'+input()+'@')
  A.append(a)
A.append(list('@'*(W+2)))

vy = [0,0,1,-1]
vx = [1,-1,0,0]
b_count = 0
ans = 0
while(1):
 b_count = 0
 tmp_list = []
 for i in range(H+2):
  if((i != 0)and(i != H+1)):
   for j in range(W+2):
    if((j != 0)and(j != W+1)):
     if(A[i][j] == '#'): 
       tmp_list.append([i,j])
       b_count += 1
 
 #終了条件
 if(b_count == H*W):
  break
  
 for i in range(len(tmp_list)):
  tmp_y,tmp_x = tmp_list[i][0],tmp_list[i][1]
  for j in range(4):
    if(A[tmp_y+vy[j]][tmp_x+vx[j]] == '.'):
      A[tmp_y+vy[j]][tmp_x+vx[j]] = '#'
 
 ans += 1
 
print(ans)      

Fixed submission:
from collections import deque

H,W = map(int,input().split())

by,bx= deque(),deque()
Map = []
Map.append('@'*(W+2))
for i in range(H):
  c = list('@'+input()+'@')
  Map.append(c)
  for j in range(W+2):
    if(c[j] == '#'):
      Map[i+1][j] = 0
      by.append(i+1),bx.append(j)
Map.append('@'*(W+2))      

cnt = 0
while(1):
  if(len(by) == 0):
    break
   
  ny,nx = by.popleft(),bx.popleft()
  vec_y,vec_x = [1,-1,0,0],[0,0,1,-1]
  for i in range(4):
      if(Map[ny+vec_y[i]][nx+vec_x[i]] == '.'):
         Map[ny+vec_y[i]][nx+vec_x[i]] = Map[ny][nx] + 1
         cnt = max(cnt, Map[ny][nx] + 1) 
         by.append(ny+vec_y[i]),bx.append(nx+vec_x[i])
  
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int,input().split())

A = []
A.append(list('@'*(W+2)))
for i in range(H):
  a = list('@'+input()+'@')
  A.append(a)
A.append(list('@'*(W+2)))

vy = [0,0,1,-1]
vx = [1,-1,0,0]
b_count = 0
ans = 0
while(1):
 b_count = 0
 tmp_list = []
 for i in range(H+2):
  if((i != 0)and(i != H+1)):
   for j in range(W+2):
    if((j != 0)and(j != W+1)):
     if(A[i][j] == '#'): 
       tmp_list.append([i,j])
       b_count += 1
 
 #終了条件
 if(b_count == H*W):
  break
  
 for i in range(len(tmp_list)):
  tmp_y,tmp_x = tmp_list[i][0],tmp_list[i][1]
  for j in range(4):
    if(A[tmp_y+vy[j]][tmp_x+vx[j]] == '.'):
      A[tmp_y+vy[j]][tmp_x+vx[j]] = '#'
 
 ans += 1
 
print(ans)      
  

Fixed submission:
from collections import deque

H,W = map(int,input().split())

by,bx= deque(),deque()
Map = []
Map.append('@'*(W+2))
for i in range(H):
  c = list('@'+input()+'@')
  Map.append(c)
  for j in range(W+2):
    if(c[j] == '#'):
      Map[i+1][j] = 0
      by.append(i+1),bx.append(j)
Map.append('@'*(W+2))      

cnt = 0
while(1):
  if(len(by) == 0):
    break
   
  ny,nx = by.popleft(),bx.popleft()
  vec_y,vec_x = [1,-1,0,0],[0,0,1,-1]
  for i in range(4):
      if(Map[ny+vec_y[i]][nx+vec_x[i]] == '.'):
         Map[ny+vec_y[i]][nx+vec_x[i]] = Map[ny][nx] + 1
         cnt = max(cnt, Map[ny][nx] + 1) 
         by.append(ny+vec_y[i]),bx.append(nx+vec_x[i])
  
print(cnt)