Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
def main():
  h,w=map(int,input().split())
  a=[list(map(lambda x:0 if x=='#' else -1,list(input()))) for _ in range(h)]
  todo=[]
  from collections import deque
  for i in range(h):
    for j in range(w):
      if a[i][j]==0:
        todo.append([i,j])
  todo=deque(todo)
  ans=0
  while todo:
    i,j=todo.popleft()
    d=a[i][j]+1
    ans=d-1
    if i>0 and a[i-1][j]==-1:
      a[i-1][j]=d
      todo.append([i-1,j])
    if i<h-1 and a[i+1][j]==-1:
      a[i+1][j]=d
      todo.append([i+1,j])
    if j>0 and a[i][j-1]==-1:
      a[i][j-1]=d
      todo.append([i,j-1])
    if j<w-1 and a[i][j+1]==-1:
      a[i][j+1]=d
      todo.append([i,j+1])
  print(ans)
if __name__=='__main__':
  #import datetime
  #print(datetime.datetime.now())
  main()
  #print(datetime.datetime.now())

Fixed submission:
h,w=map(int,input().split())
a=[input() for _ in range(h)]
seen=[[-1]*w for _ in range(h)]
from collections import deque
todo=deque([])
for hi in range(h):
  for wi in range(w):
    if a[hi][wi]=='#':
      seen[hi][wi]=0
      todo.append((hi,wi,0))
while len(todo)>0:
  hi,wi,i=todo.popleft()
  if hi>0 and seen[hi-1][wi]==-1:
    todo.append((hi-1,wi,i+1))
    seen[hi-1][wi]=i+1
  if hi<h-1 and seen[hi+1][wi]==-1:
    todo.append((hi+1,wi,i+1))
    seen[hi+1][wi]=i+1
  if wi>0 and seen[hi][wi-1]==-1:
    todo.append((hi,wi-1,i+1))
    seen[hi][wi-1]=i+1
  if wi<w-1 and seen[hi][wi+1]==-1:
    todo.append((hi,wi+1,i+1))
    seen[hi][wi+1]=i+1
print(max([max(seeni) for seeni in seen]))

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
a=[list(map(lambda x:0 if x=='#' else -1,list(input()))) for _ in range(h)]
todo=[]
from collections import deque
for i in range(h):
  for j in range(w):
    if a[i][j]==0:
      todo.append([i,j])
seen=[[0]*w for _ in range(h)]
from collections import deque
todo=deque(todo)
ans=0
while todo:
  i,j=todo.popleft()
  d=a[i][j]+1
  ans=d-1
  if i>0 and a[i-1][j]==-1:
    a[i-1][j]=d
    todo.append([i-1,j])
  if i<h-1 and a[i+1][j]==-1:
    a[i+1][j]=d
    todo.append([i+1,j])
  if j>0 and a[i][j-1]==-1:
    a[i][j-1]=d
    todo.append([i,j-1])
  if j<w-1 and a[i][j+1]==-1:
    a[i][j+1]=d
    todo.append([i,j+1])

print(ans)
#for ai in a:
#  print(ai)


Fixed submission:
h,w=map(int,input().split())
a=[input() for _ in range(h)]
seen=[[-1]*w for _ in range(h)]
from collections import deque
todo=deque([])
for hi in range(h):
  for wi in range(w):
    if a[hi][wi]=='#':
      seen[hi][wi]=0
      todo.append((hi,wi,0))
while len(todo)>0:
  hi,wi,i=todo.popleft()
  if hi>0 and seen[hi-1][wi]==-1:
    todo.append((hi-1,wi,i+1))
    seen[hi-1][wi]=i+1
  if hi<h-1 and seen[hi+1][wi]==-1:
    todo.append((hi+1,wi,i+1))
    seen[hi+1][wi]=i+1
  if wi>0 and seen[hi][wi-1]==-1:
    todo.append((hi,wi-1,i+1))
    seen[hi][wi-1]=i+1
  if wi<w-1 and seen[hi][wi+1]==-1:
    todo.append((hi,wi+1,i+1))
    seen[hi][wi+1]=i+1
print(max([max(seeni) for seeni in seen]))

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
a=[list(map(lambda x:int(x=='#'),list(input()))) for _ in range(h)]
todo=[]
next_todo=[]
from collections import deque
for i in range(h):
  for j in range(w):
    if a[i][j]==1:
      next_todo.append([i,j])
seen=[[0]*w for _ in range(h)]
ans=0
while next_todo:
  todo=next_todo.copy()
  next_todo=[]
  while todo:
    i,j=todo.pop()
    if i>0 and a[i-1][j]==0:
      a[i-1][j]=1
      next_todo.append([i-1,j])
    if i<h-1 and a[i+1][j]==0:
      a[i+1][j]=1
      next_todo.append([i+1,j])
    if j>0 and a[i][j-1]==0:
      a[i][j-1]=1
      next_todo.append([i,j-1])
    if j<w-1 and a[i][j+1]==0:
      a[i][j+1]=1
      next_todo.append([i,j+1])
  if next_todo:
    ans+=1
print(ans)


Fixed submission:
h,w=map(int,input().split())
a=[input() for _ in range(h)]
seen=[[-1]*w for _ in range(h)]
from collections import deque
todo=deque([])
for hi in range(h):
  for wi in range(w):
    if a[hi][wi]=='#':
      seen[hi][wi]=0
      todo.append((hi,wi,0))
while len(todo)>0:
  hi,wi,i=todo.popleft()
  if hi>0 and seen[hi-1][wi]==-1:
    todo.append((hi-1,wi,i+1))
    seen[hi-1][wi]=i+1
  if hi<h-1 and seen[hi+1][wi]==-1:
    todo.append((hi+1,wi,i+1))
    seen[hi+1][wi]=i+1
  if wi>0 and seen[hi][wi-1]==-1:
    todo.append((hi,wi-1,i+1))
    seen[hi][wi-1]=i+1
  if wi<w-1 and seen[hi][wi+1]==-1:
    todo.append((hi,wi+1,i+1))
    seen[hi][wi+1]=i+1
print(max([max(seeni) for seeni in seen]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
def main():
  h,w=map(int,input().split())
  a=[input() for _ in range(h)]
  seen=[[-1]*w for _ in range(h)]
  from collections import deque
  todo=deque([])
  for hi,ai in enumerate(a):
    for wj,aij in enumerate(ai):
      if aij=='#':
        seen[hi][wj]=0
        todo.append((hi,wj,0))
  while len(todo)>0:
    hi,wi,i=todo.popleft()
    if hi>0 and seen[hi-1][wi]==-1:
      todo.append((hi-1,wi,i+1))
      seen[hi-1][wi]=i+1
    if hi<h-1 and seen[hi+1][wi]==-1:
      todo.append((hi+1,wi,i+1))
      seen[hi+1][wi]=i+1
    if wi>0 and seen[hi][wi-1]==-1:
      todo.append((hi,wi-1,i+1))
      seen[hi][wi-1]=i+1
    if wi<w-1 and seen[hi][wi+1]==-1:
      todo.append((hi,wi+1,i+1))
      seen[hi][wi+1]=i+1
  print(i)
if __name__=='__main__':
  main()

Fixed submission:
h,w=map(int,input().split())
a=[input() for _ in range(h)]
seen=[[-1]*w for _ in range(h)]
from collections import deque
todo=deque([])
for hi in range(h):
  for wi in range(w):
    if a[hi][wi]=='#':
      seen[hi][wi]=0
      todo.append((hi,wi,0))
while len(todo)>0:
  hi,wi,i=todo.popleft()
  if hi>0 and seen[hi-1][wi]==-1:
    todo.append((hi-1,wi,i+1))
    seen[hi-1][wi]=i+1
  if hi<h-1 and seen[hi+1][wi]==-1:
    todo.append((hi+1,wi,i+1))
    seen[hi+1][wi]=i+1
  if wi>0 and seen[hi][wi-1]==-1:
    todo.append((hi,wi-1,i+1))
    seen[hi][wi-1]=i+1
  if wi<w-1 and seen[hi][wi+1]==-1:
    todo.append((hi,wi+1,i+1))
    seen[hi][wi+1]=i+1
print(max([max(seeni) for seeni in seen]))

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
a=[input() for _ in range(h)]

seen=[[-1]*w for _ in range(h)]
from collections import deque
todo=deque([])
for hi in range(h):
  for wi in range(w):
    if a[hi][wi]=='#':
      seen[hi][wi]=0
      todo.append((hi,wi,0))
while len(todo)>0:
  hi,wi,i=todo.popleft()
  if hi>0 and seen[hi-1][wi]==-1:
    todo.append((hi-1,wi,i+1))
    seen[hi-1][wi]=i+1
  if hi<h-1 and seen[hi+1][wi]==-1:
    todo.append((hi+1,wi,i+1))
    seen[hi+1][wi]=i+1
  if wi>0 and seen[hi][wi-1]==-1:
    todo.append((hi,wi-1,i+1))
    seen[hi][wi-1]=i+1
  if wi<w-1 and seen[hi][wi+1]==-1:
    todo.append((hi,wi+1,i+1))
    seen[hi][wi+1]=i+1
print(max([max(seeni) for seeni in seen]))


Fixed submission:
h,w=map(int,input().split())
a=[input() for _ in range(h)]
seen=[[-1]*w for _ in range(h)]
from collections import deque
todo=deque([])
for hi in range(h):
  for wi in range(w):
    if a[hi][wi]=='#':
      seen[hi][wi]=0
      todo.append((hi,wi,0))
while len(todo)>0:
  hi,wi,i=todo.popleft()
  if hi>0 and seen[hi-1][wi]==-1:
    todo.append((hi-1,wi,i+1))
    seen[hi-1][wi]=i+1
  if hi<h-1 and seen[hi+1][wi]==-1:
    todo.append((hi+1,wi,i+1))
    seen[hi+1][wi]=i+1
  if wi>0 and seen[hi][wi-1]==-1:
    todo.append((hi,wi-1,i+1))
    seen[hi][wi-1]=i+1
  if wi<w-1 and seen[hi][wi+1]==-1:
    todo.append((hi,wi+1,i+1))
    seen[hi][wi+1]=i+1
print(max([max(seeni) for seeni in seen]))