Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline

H,W = map(int,input().split())
D = [list(input()) for i in range(H)]
ans = 0
dist = [[float("inf")]*W for i in range(H)]

for sy in range(H):
    for sx in range(W):
        if D[sy][sx] == "#":
            Q = deque()
            Q.append((sx,sy))
            dist[sy][sx] = 0
            visited = [[0]*W for i in range(H)]
            dx = [1,0,-1,0]
            dy = [0,-1,0,1]
            while Q:
                x,y = Q.popleft()
                for i in range(4):
                    nx = x+dx[i]
                    ny = y+dy[i]
                    if 0<=nx<=W-1 and 0<=ny<=H-1 and visited[ny][nx] == 0 and D[ny][nx] == ".":
                        Q.append((nx,ny))
                        visited[ny][nx] = 1
                        dist[ny][nx] = min(dist[y][x]+1,dist[ny][nx])

for i in range(H):
    for j in range(W):
        if D[i][j] == ".":
            ans = max(ans,dist[i][j])
print(ans)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]

INF = 99999
dp = [[-1]*W for i in range(H)]
q = deque()
for y, row in enumerate(A):
  for x,c in enumerate(row):
    if c == "#":
      dp[y][x] = 0
      q.append((y,x))
while q:
  y,x = q.popleft()
  d = dp[y][x]
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dp[ny][nx] == -1):
      dp[ny][nx] = d + 1
      q.append((ny,nx))
print(max(max(row) for row in dp))

Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
input = sys.stdin.readline

H,W = map(int,input().split())
D = [list(input()) for i in range(H)]
ans = 0

for i in range(H):
    for j in range(W):
        sy = i
        sx = j
        if D[sy][sx] == ".":
            Q = deque()
            Q.append((sx,sy))
            dist = [[-1]*W for i in range(H)]
            dist[sy][sx] = 0
            dx = [1,0,-1,0]
            dy = [0,-1,0,1]
            while Q:
                x,y = Q.popleft()
                if D[y][x] == "#":
                    d = dist[y][x]
                    ans = max(ans,d)
                    break
                for i in range(4):
                    nx = x+dx[i]
                    ny = y+dy[i]
                    if 0<=nx<=W-1 and 0<=ny<=H-1 and dist[ny][nx] == -1:
                        Q.append((nx,ny))
                        dist[ny][nx] = dist[y][x]+1

print(ans)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]

INF = 99999
dp = [[-1]*W for i in range(H)]
q = deque()
for y, row in enumerate(A):
  for x,c in enumerate(row):
    if c == "#":
      dp[y][x] = 0
      q.append((y,x))
while q:
  y,x = q.popleft()
  d = dp[y][x]
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dp[ny][nx] == -1):
      dp[ny][nx] = d + 1
      q.append((ny,nx))
print(max(max(row) for row in dp))

Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
input = sys.stdin.readline

H,W = map(int,input().split())
D = [list(input()) for i in range(H)]
ans = 0

for i in range(H):
    for j in range(W):
        sy = i
        sx = j
        if D[sy][sx] == ".":
            Q = deque()
            Q.append((sx,sy))
            dist = [[-1]*W for i in range(H)]
            dist[sy][sx] = 0
            dx = [1,0,-1,0]
            dy = [0,-1,0,1]
            while Q:
                x,y = Q.popleft()
                if D[y][x] == "#":
                    d = dist[y][x]
                    ans = max(ans,d)
                    break
                for i in range(4):
                    nx = x+dx[i]
                    ny = y+dy[i]
                    if 0<=nx<=W-1 and 0<=ny<=H-1 and dist[ny][nx] == -1:
                        Q.append((nx,ny))
                        dist[ny][nx] = dist[y][x]+1

print(ans)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]

INF = 99999
dp = [[-1]*W for i in range(H)]
q = deque()
for y, row in enumerate(A):
  for x,c in enumerate(row):
    if c == "#":
      dp[y][x] = 0
      q.append((y,x))
while q:
  y,x = q.popleft()
  d = dp[y][x]
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dp[ny][nx] == -1):
      dp[ny][nx] = d + 1
      q.append((ny,nx))
print(max(max(row) for row in dp))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input = sys.stdin.readline

H, W = map(int, input().split())
table = []
dist = [[-1]*W for i in range(H)]
Q = deque()
dx = [0,1,0,-1]
dy = [1,0,-1,0]
ans = 0

for y in range(H):
    A = list(input())
    for x in range(W):
        if A[x] == "#":
            Q.append((y,x))
            dist[y][x] = 0
    table.append(A)

while Q:
    y,x = Q.popleft()
    for i in range(4):
        ny = y+dy[i]
        nx = x+dx[i]
        if 0<=ny<H and 0<=nx<W and dist[ny][nx] == -1 and table[ny][nx] == ".":
            dist[ny][nx] = dist[y][x]+1
            Q.append((ny,nx))
for i in range(H):
    ans = max(ans,max(dist[i]))
print(ans)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]

INF = 99999
dp = [[-1]*W for i in range(H)]
q = deque()
for y, row in enumerate(A):
  for x,c in enumerate(row):
    if c == "#":
      dp[y][x] = 0
      q.append((y,x))
while q:
  y,x = q.popleft()
  d = dp[y][x]
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dp[ny][nx] == -1):
      dp[ny][nx] = d + 1
      q.append((ny,nx))
print(max(max(row) for row in dp))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H, W = map(int, input().split())
C = [list(input()) for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]
Q = deque()
dist = [[99999]*W for i in range(H)]
for i in range(H):
  for j in range(W):
    if C[i][j] == "#":
      dist[i][j] = 0
      Q.append((i,j))
      while Q:
        y,x = Q.popleft()
        for k in range(4):
          ny = y + Y[k]
          nx = x + X[k]
          if not (0 <= nx < W):
            continue
          if not (0 <= ny < H):
            continue
          if not (C[ny][nx] == "."):
            continue
          if not (dist[ny][nx] > dist[y][x]+1):
            continue
          Q.append((ny,nx))
          dist[ny][nx] = dist[y][x] + 1
ans = 0
for i in range(H):
  ans = max(ans,max(dist[i]))
print(ans)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]

INF = 99999
dp = [[-1]*W for i in range(H)]
q = deque()
for y, row in enumerate(A):
  for x,c in enumerate(row):
    if c == "#":
      dp[y][x] = 0
      q.append((y,x))
while q:
  y,x = q.popleft()
  d = dp[y][x]
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dp[ny][nx] == -1):
      dp[ny][nx] = d + 1
      q.append((ny,nx))
print(max(max(row) for row in dp))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from collections import deque
H, W = map(int, input().split())
C = [list(input()) for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]
Q = deque()
dist = [[99999]*W for i in range(H)]
for i in range(H):
  for j in range(W):
    if C[i][j] == "#":
      dist[i][j] = 0
      Q.append((i,j))
      while Q:
        y,x = Q.popleft()
        for k in range(4):
          ny = y + Y[k]
          nx = x + X[k]
          if not (0 <= nx < W):
            continue
          if not (0 <= ny < H):
            continue
          if not (C[ny][nx] == "."):
            continue
          if not (dist[ny][nx] > dist[y][x]+1):
            continue
          Q.append((ny,nx))
          dist[ny][nx] = dist[y][x] + 1
ans = 0
for i in range(H):
  ans = max(ans,max(dist[i]))
print(ans)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]

INF = 99999
dp = [[-1]*W for i in range(H)]
q = deque()
for y, row in enumerate(A):
  for x,c in enumerate(row):
    if c == "#":
      dp[y][x] = 0
      q.append((y,x))
while q:
  y,x = q.popleft()
  d = dp[y][x]
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dp[ny][nx] == -1):
      dp[ny][nx] = d + 1
      q.append((ny,nx))
print(max(max(row) for row in dp))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from collections import deque
H, W = map(int, input().split())
C = [list(input()) for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]
Q = deque()
dist = [[0]*W for i in range(H)]
for i in range(H):
  for j in range(W):
    if C[i][j] == "#":
      Q.append((i,j))
      while Q:
        y,x = Q.popleft()
        for k in range(4):
          ny = y + Y[k]
          nx = x + X[k]
          if not (0 <= nx < W):
            continue
          if not (0 <= ny < H):
            continue
          if not (C[ny][nx] == "."):
            continue
          if not (dist[ny][nx] == 0 or dist[ny][nx] > dist[y][x]+1):
            continue
          Q.append((ny,nx))
          dist[ny][nx] = dist[y][x] + 1
ans = 0
for i in range(H):
  ans = max(ans,max(dist[i]))
print(ans)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]

INF = 99999
dp = [[-1]*W for i in range(H)]
q = deque()
for y, row in enumerate(A):
  for x,c in enumerate(row):
    if c == "#":
      dp[y][x] = 0
      q.append((y,x))
while q:
  y,x = q.popleft()
  d = dp[y][x]
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dp[ny][nx] == -1):
      dp[ny][nx] = d + 1
      q.append((ny,nx))
print(max(max(row) for row in dp))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from collections import deque
H, W = map(int, input().split())
C = [list(input()) for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]
Q = deque()
dist = [[0]*W for i in range(H)]
for i in range(H):
  for j in range(W):
    if C[i][j] == "#":
      Q.append((i,j))
      while Q:
        y,x = Q.popleft()
        for k in range(4):
          ny = y + Y[k]
          nx = x + X[k]
          if (0 <= nx < W) and (0 <= ny < H) and (C[ny][nx] == ".") and (dist[ny][nx] == 0 or dist[ny][nx] > dist[y][x]+1):
            Q.append((ny,nx))
            dist[ny][nx] = dist[y][x] + 1
ans = 0
for i in range(H):
  ans = max(ans,max(dist[i]))
print(ans)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]

INF = 99999
dp = [[-1]*W for i in range(H)]
q = deque()
for y, row in enumerate(A):
  for x,c in enumerate(row):
    if c == "#":
      dp[y][x] = 0
      q.append((y,x))
while q:
  y,x = q.popleft()
  d = dp[y][x]
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dp[ny][nx] == -1):
      dp[ny][nx] = d + 1
      q.append((ny,nx))
print(max(max(row) for row in dp))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from collections import deque
H, W = map(int, input().split())
C = [list(input()) for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]
Q = deque()
dist = [[0]*W for i in range(H)]
for i in range(H):
  for j in range(W):
    if C[i][j] == "#":
      Q.append((i,j))
      while Q:
        y,x = Q.popleft()
        for k in range(4):
          ny = y + Y[k]
          nx = x + X[k]
          if (0 <= nx < W) and (0 <= ny < H) and (C[ny][nx] == ".") and (dist[ny][nx] == 0 or dist[ny][nx] > dist[y][x]+1):
            Q.append((ny,nx))
            dist[ny][nx] = dist[y][x] + 1
ans = 0
for i in range(H):
  ans = max(ans,max(dist[i]))
print(ans)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]

INF = 99999
dp = [[-1]*W for i in range(H)]
q = deque()
for y, row in enumerate(A):
  for x,c in enumerate(row):
    if c == "#":
      dp[y][x] = 0
      q.append((y,x))
while q:
  y,x = q.popleft()
  d = dp[y][x]
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dp[ny][nx] == -1):
      dp[ny][nx] = d + 1
      q.append((ny,nx))
print(max(max(row) for row in dp))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H, W = map(int, input().split())
C = []
Q = deque()
dist = [[-1]*W for i in range(H)]

for i in range(H):
  s = list(input())
  yxidx = [(i,x) for x,v in enumerate(s) if v == "#"]
  for (y, x) in yxidx:
    Q.append((y,x))
    dist[y][x] = 0
  C.append(s)
X = [1,0,-1,0]
Y = [0,-1,0,1]


while Q:
  y,x = Q.popleft()
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dist[ny][nx] == -1):
      dist[ny][nx] = dist[y][x] + 1
      Q.append((ny,nx))

ans = 0
for i in range(H):
  ans = max(ans,max(dist[i]))
print(ans)


Fixed submission:
from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]

INF = 99999
dp = [[-1]*W for i in range(H)]
q = deque()
for y, row in enumerate(A):
  for x,c in enumerate(row):
    if c == "#":
      dp[y][x] = 0
      q.append((y,x))
while q:
  y,x = q.popleft()
  d = dp[y][x]
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dp[ny][nx] == -1):
      dp[ny][nx] = d + 1
      q.append((ny,nx))
print(max(max(row) for row in dp))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H, W = map(int, input().split())
C = []
Q = deque()
dist = [[-1]*W for i in range(H)]

for i in range(H):
  s = list(input())
  yxidx = [(i,x) for x,v in enumerate(s) if v == "#"]
  for (y, x) in yxidx:
    Q.append((y,x))
    dist[y][x] = 0
  C.append(s)
X = [1,0,-1,0]
Y = [0,-1,0,1]


while Q:
  y,x = Q.popleft()
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dist[ny][nx] == -1) and (C[ny][nx] != "#"):
      dist[ny][nx] = dist[y][x] + 1
      Q.append((ny,nx))

ans = 0
for i in range(H):
  ans = max(ans,max(dist[i]))
print(ans)


Fixed submission:
from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]

INF = 99999
dp = [[-1]*W for i in range(H)]
q = deque()
for y, row in enumerate(A):
  for x,c in enumerate(row):
    if c == "#":
      dp[y][x] = 0
      q.append((y,x))
while q:
  y,x = q.popleft()
  d = dp[y][x]
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dp[ny][nx] == -1):
      dp[ny][nx] = d + 1
      q.append((ny,nx))
print(max(max(row) for row in dp))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H, W = map(int, input().split())
C = [list(input()) for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]
INF = 10**9

Q = deque()
dist = [[INF]*W for i in range(H)]

for x in range(W):
  for y in range(H):
    if C[y][x] == "#":
      Q.append((y,x))
      dist[y][x] = 0
      while Q:
        y,x = Q.popleft()
        for i in range(4):
          nx = x + X[i]
          ny = y + Y[i]
          if (0 <= nx < W) and (0 <= ny < H) and dist[y][x]+1 <= dist[ny][nx] and (C[ny][nx] != "#"):
            dist[ny][nx] = dist[y][x] + 1
            Q.append((ny,nx))
ans = 0
for i in range(H):
  ans = max(ans,max(dist[i]))
print(ans)


Fixed submission:
from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]

INF = 99999
dp = [[-1]*W for i in range(H)]
q = deque()
for y, row in enumerate(A):
  for x,c in enumerate(row):
    if c == "#":
      dp[y][x] = 0
      q.append((y,x))
while q:
  y,x = q.popleft()
  d = dp[y][x]
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dp[ny][nx] == -1):
      dp[ny][nx] = d + 1
      q.append((ny,nx))
print(max(max(row) for row in dp))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H, W = map(int, input().split())
C = [list(input()) for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]
INF = 10**9

Q = deque()
dist = [[INF]*W for i in range(H)]

for x in range(W):
  for y in range(H):
    if C[y][x] == "#":
      visited = [[0]*W for i in range(H)]
      visited[y][x] = 1
      Q.append((y,x))
      dist[y][x] = 0
      while Q:
        y,x = Q.popleft()
        for i in range(4):
          nx = x + X[i]
          ny = y + Y[i]
          if (0 <= nx < W) and (0 <= ny < H) and (visited[ny][nx] == 0) and (C[ny][nx] != "#"):
            visited[ny][nx] = 1
            dist[ny][nx] = min(dist[y][x] + 1,dist[ny][nx])
            Q.append((ny,nx))
ans = 0
for i in range(H):
  ans = max(ans,max(dist[i]))
print(ans)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]

INF = 99999
dp = [[-1]*W for i in range(H)]
q = deque()
for y, row in enumerate(A):
  for x,c in enumerate(row):
    if c == "#":
      dp[y][x] = 0
      q.append((y,x))
while q:
  y,x = q.popleft()
  d = dp[y][x]
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dp[ny][nx] == -1):
      dp[ny][nx] = d + 1
      q.append((ny,nx))
print(max(max(row) for row in dp))

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

B = []

for i in range(H):
  for j in range(W):
    tmp = []
    for h in range(H):
      for w in range(W):
        if A[h][w] == "#":
          tmp.append(abs(h-i)+abs(w-j))
    B.append(min(tmp))
print(max(B))

Fixed submission:
from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]

INF = 99999
dp = [[-1]*W for i in range(H)]
q = deque()
for y, row in enumerate(A):
  for x,c in enumerate(row):
    if c == "#":
      dp[y][x] = 0
      q.append((y,x))
while q:
  y,x = q.popleft()
  d = dp[y][x]
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dp[ny][nx] == -1):
      dp[ny][nx] = d + 1
      q.append((ny,nx))
print(max(max(row) for row in dp))