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

H, W = map(int, input().split())
A = [input() for _ in range(H)]
ans = 0
for h in range(H):
  for w in range(W):
    if A[h][w] == ".":
      dist = 0
      found = False
      while not found:
        dist += 1
        for dx in range(dist+1):
          dy = dist-dx
          xs = deque([])
          ys = deque([])
          if h-dy >= 0:
            ys.append(h-dy)
          if h+dy < H:
            ys.append(h+dy)
          if w-dx >= 0:
            xs.append(w-dx)
          if w+dx < W:
            xs.append(w+dx)
          for y in ys:
            for x in xs:
              if A[y][x] == "#":
                found = True
                break
            if found:
               break
          if found:
            break
      ans = max(dist, ans)
print(ans)



Fixed submission:
from collections import deque

H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]
blacks = deque([])
for h in range(H):
  for w in range(W):
    if A[h][w] == "#":
      blacks.append((h, w))
count = 0
while len(blacks) > 0:
  newblacks = deque([])
  while len(blacks) > 0:
    b = blacks.popleft()
    for y, x in zip((b[0]-1, b[0], b[0], b[0]+1), (b[1], b[1]-1, b[1]+1, b[1])):
      if y < 0 or y >= H or x < 0 or x >= W:
        continue
      if A[y][x] == ".":
        newblacks.append((y, x))
      A[y][x] = "#"
  blacks = newblacks
  count += 1
print(count-1)

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

H, W = map(int, input().split())
A = [input() for _ in range(H)]
blacks = deque([])
for h in range(H):
  for w in range(W):
    if A[h][w] == "#":
      blacks.append((h, w))
ans = 0
for h in range(H):
  for w in range(W):
    if A[h][w] == ".":
      dist = 10000
      for b in blacks:
        dist = min(dist, abs(b[0]-h)+abs(b[1]-w))
        if dist == 1:
          break
      ans = max(dist, ans)
print(ans)



Fixed submission:
from collections import deque

H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]
blacks = deque([])
for h in range(H):
  for w in range(W):
    if A[h][w] == "#":
      blacks.append((h, w))
count = 0
while len(blacks) > 0:
  newblacks = deque([])
  while len(blacks) > 0:
    b = blacks.popleft()
    for y, x in zip((b[0]-1, b[0], b[0], b[0]+1), (b[1], b[1]-1, b[1]+1, b[1])):
      if y < 0 or y >= H or x < 0 or x >= W:
        continue
      if A[y][x] == ".":
        newblacks.append((y, x))
      A[y][x] = "#"
  blacks = newblacks
  count += 1
print(count-1)

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

H, W = map(int, input().split())
A = [input() for _ in range(H)]
blacks = deque([])
for h in range(H):
  for w in range(W):
    if A[h][w] == "#":
      blacks.append((h, w))
ans = 0
for h in range(H):
  for w in range(W):
    if A[h][w] == ".":
      dist = 10000
      for b in blacks:
        dist = min(dist, abs(b[0]-h)+abs(b[1]-w))
      ans = max(dist, ans)
print(ans)



Fixed submission:
from collections import deque

H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]
blacks = deque([])
for h in range(H):
  for w in range(W):
    if A[h][w] == "#":
      blacks.append((h, w))
count = 0
while len(blacks) > 0:
  newblacks = deque([])
  while len(blacks) > 0:
    b = blacks.popleft()
    for y, x in zip((b[0]-1, b[0], b[0], b[0]+1), (b[1], b[1]-1, b[1]+1, b[1])):
      if y < 0 or y >= H or x < 0 or x >= W:
        continue
      if A[y][x] == ".":
        newblacks.append((y, x))
      A[y][x] = "#"
  blacks = newblacks
  count += 1
print(count-1)

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

H, W = map(int, input().split())
A = [input() for _ in range(H)]
blacks = deque([])
for h in range(H):
  for w in range(W):
    if A[h][w] == "#":
      blacks.append((h, w))
ans = 0
for h in range(H):
  for w in range(W):
    if A[h][w] == ".":
      dist = 10000
      for b in blacks:
        dist = min(dist, abs(b[0]-h)+abs(b[1]-w))
      ans = max(dist, ans)
print(ans)



Fixed submission:
from collections import deque

H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]
blacks = deque([])
for h in range(H):
  for w in range(W):
    if A[h][w] == "#":
      blacks.append((h, w))
count = 0
while len(blacks) > 0:
  newblacks = deque([])
  while len(blacks) > 0:
    b = blacks.popleft()
    for y, x in zip((b[0]-1, b[0], b[0], b[0]+1), (b[1], b[1]-1, b[1]+1, b[1])):
      if y < 0 or y >= H or x < 0 or x >= W:
        continue
      if A[y][x] == ".":
        newblacks.append((y, x))
      A[y][x] = "#"
  blacks = newblacks
  count += 1
print(count-1)