Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque

def agc033_a():
    H, W = map(int, readline().split())
    dist = [[-1] * W for _ in range(H)]
    que = deque()
    for i, ln in enumerate(read().split()):
        for j, c in enumerate(ln.strip().decode('UTF-8')):
            if c == '#':
                que.append((i, j))
                dist[i][j] = 0

    while que:
        x, y = que.popleft()
        for i, j in ((x-1, y), (x, y-1), (x, y+1), (x+1, y)):
            if i < 0 or H-1 < i or j < 0 or W-1 < j: continue
            if dist[i][j] != -1: continue
            dist[i][j] = dist[x][y] + 1
            que.append((i, j))

    ans = 0
    for row in dist:
        ans = max(max(row), ans)
    print(ans)

agc033_a()

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque

def agc033_a():
    H, W = map(int, readline().split())
    dist = [[-1] * W for _ in range(H)]
    que = deque()
    for i, ln in enumerate(read().split()):
        for j, c in enumerate(ln.strip().decode('UTF-8')):
            if c == '#':
                que.append((i, j))
                dist[i][j] = 0

    while que:
        x, y = que.popleft()
        for i, j in ((x-1, y), (x, y-1), (x, y+1), (x+1, y)):
            if i < 0 or H-1 < i or j < 0 or W-1 < j: continue
            if dist[i][j] != -1: continue
            dist[i][j] = dist[x][y] + 1
            que.append((i, j))

    ans = 0
    for row in dist:
        ans = max(max(row), ans)
    print(ans)

agc033_a()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque
import numpy as np

def agc033_a():
    H, W = map(int, readline().split())
    grid = np.full((H+2, W+2), '#', dtype=object)
    for i, ln in enumerate(read().split()):
        grid[i+1, 1:W+1] = [str(x) for x in ln.strip().decode('UTF-8')]

    que = deque()
    dist = np.ones((H+2, W+2), dtype=int)
    dist *= -1

    for i in range(1, H+1):
        for j in range(1, W+1):
            if grid[i, j] == '#':
                que.append((i, j))
                dist[i, j] = 0

    while que:
        x, y = que.popleft()
        for i, j in ((x-1, y), (x, y-1), (x, y+1), (x+1, y)):
            if grid[i, j] == '#': continue
            if dist[i, j] != -1: continue
            dist[i, j] = dist[x, y] + 1
            que.append((i, j))

    ans = dist.max()
    print(ans)

agc033_a()

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque

def agc033_a():
    H, W = map(int, readline().split())
    dist = [[-1] * W for _ in range(H)]
    que = deque()
    for i, ln in enumerate(read().split()):
        for j, c in enumerate(ln.strip().decode('UTF-8')):
            if c == '#':
                que.append((i, j))
                dist[i][j] = 0

    while que:
        x, y = que.popleft()
        for i, j in ((x-1, y), (x, y-1), (x, y+1), (x+1, y)):
            if i < 0 or H-1 < i or j < 0 or W-1 < j: continue
            if dist[i][j] != -1: continue
            dist[i][j] = dist[x][y] + 1
            que.append((i, j))

    ans = 0
    for row in dist:
        ans = max(max(row), ans)
    print(ans)

agc033_a()

Buggy python submission (verdict: Runtime Error):
import math
def agc033_a():
  h, w = map(int, input().split())
  grid = [[s for s in str(input())] for _ in range(h)]

  # 黒マスからの距離(#は0)
  dist = [[math.inf] * w for _ in range(h)]
  for i in range(h):
    for j in range(w):
      if grid[i][j] == '#':
        dist[i][j] = 0

  def ask_dist(i, j):
    adj = math.inf
    if 0 < i: adj = min(adj, dist[i-1][j])
    if i < h-1: adj = min(adj, dist[i+1][j])
    if 0 < j: adj = min(adj, dist[i][j-1])
    if j < w-1: adj = min(adj, dist[i][j+1])
    if adj != math.inf:
      return adj + 1
    else:
      return math.inf

  # 1往復したら距離確定する？？ TLEするかも？？
  d_max = 0
  for i in range(h):
    for j in range(w):
      if dist[i][j] != math.inf: continue
      d_tmp = ask_dist(i, j)
      if d_tmp != math.inf:
        dist[i][j] = d_tmp
        d_max = max(d_max, d_tmp)
  for i in range(h-1, -1, -1):
    for j in range(w-1, -1, -1):
      if dist[i][j] != math.inf: continue
      d_tmp = ask_dist(i, j)
      if d_tmp != math.inf:
        dist[i][j] = d_tmp
        d_max = max(d_max, d_tmp)
  print(d_max)

agc033_a()

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque

def agc033_a():
    H, W = map(int, readline().split())
    dist = [[-1] * W for _ in range(H)]
    que = deque()
    for i, ln in enumerate(read().split()):
        for j, c in enumerate(ln.strip().decode('UTF-8')):
            if c == '#':
                que.append((i, j))
                dist[i][j] = 0

    while que:
        x, y = que.popleft()
        for i, j in ((x-1, y), (x, y-1), (x, y+1), (x+1, y)):
            if i < 0 or H-1 < i or j < 0 or W-1 < j: continue
            if dist[i][j] != -1: continue
            dist[i][j] = dist[x][y] + 1
            que.append((i, j))

    ans = 0
    for row in dist:
        ans = max(max(row), ans)
    print(ans)

agc033_a()