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

def main():
  H, W = map(int, input().split())
  maps = [[j=="#" for j in input()] for i in range(H)]
  q = deque([[i, j] for i in range(H) for j in range(W) if maps[i][j]])
  count = 0
  while True:
    nq = deque()
    while q:
      x, y = q.popleft()
      if x > 0 and not maps[x-1][y]:
        maps[x-1][y] = True
        nq.append([x-1,y])
      if y > 0 and not maps[x][y-1]:
        maps[x][y-1] = True
        nq.append([x,y-1])
      if x < H-1 and not maps[x+1][y]:
        maps[x+1][y] = True
        nq.append([x+1,y])
      if y < W-1 and not maps[x][y+1]:
        maps[x][y+1] = True
        nq.append([x,y+1])
    if nq:
      q = copy.copy(nq)
    else:
        break
    count += 1
  print(count)

if __name__ == "__main__":
  main()

Fixed submission:
# python には結構厳しいTLE・・・python以外のお勉強時間ないよ～( ;∀;)
# . から見た # の最大距離の方が楽ではあるが・・・
# 嫌いだけど def main も使ってみた．
from collections import deque
import copy
 
def main():
  H, W = list(map(int, input().split()))
  L = [[j=="#" for j in input()] for i in range(H)]
  q = deque([(i, j) for i in range(H) for j in range(W) if L[i][j]])
  cands = [(0, -1), (0, 1), (-1, 0), (1, 0)]
  result = 0
  while True:
    nq = deque()
    while q:
      i, j = q.popleft()
      if i > 0 and not L[i-1][j]:
        L[i-1][j] = True
        nq.append((i-1, j))
      if j > 0 and not L[i][j-1]:
        L[i][j-1] = True
        nq.append((i, j-1))
      if i < H-1 and not L[i+1][j]:
        L[i+1][j] = True
        nq.append((i+1, j))
      if j < W-1 and not L[i][j+1]:
        L[i][j+1] = True
        nq.append((i, j+1))
    if nq:
      q = copy.copy(nq)
    else:
      break    
    result += 1
  print(result)
 
if __name__ == "__main__":
  main()

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

def main():
  H, W = map(int, input().split())
  maps = [[j=="#" for j in input()] for i in range(H)]
  q = deque([(i, j) for i in range(H) for j in range(W) if maps[i][j]])
  count = 0
  while True:
    nq = deque()
    while q:
      x, y = q.popleft()
      if x > 0 and not maps[x-1][y]:
        maps[x-1][y] = True
        nq.append([x-1,y])
      if y > 0 and not maps[x][y-1]:
        maps[x][y-1] = True
        nq.append([x,y-1])
      if x < H-1 and not maps[x+1][y]:
        maps[x+1][y] = True
        nq.append([x+1,y])
      if y < W-1 and not maps[x][y+1]:
        maps[x][y+1] = True
        nq.append([x,y+1])
    if nq:
      q = copy.copy(nq)
    else:
        break
    count += 1
  print(count)

if __name__ == "__main__":
  main()

Fixed submission:
# python には結構厳しいTLE・・・python以外のお勉強時間ないよ～( ;∀;)
# . から見た # の最大距離の方が楽ではあるが・・・
# 嫌いだけど def main も使ってみた．
from collections import deque
import copy
 
def main():
  H, W = list(map(int, input().split()))
  L = [[j=="#" for j in input()] for i in range(H)]
  q = deque([(i, j) for i in range(H) for j in range(W) if L[i][j]])
  cands = [(0, -1), (0, 1), (-1, 0), (1, 0)]
  result = 0
  while True:
    nq = deque()
    while q:
      i, j = q.popleft()
      if i > 0 and not L[i-1][j]:
        L[i-1][j] = True
        nq.append((i-1, j))
      if j > 0 and not L[i][j-1]:
        L[i][j-1] = True
        nq.append((i, j-1))
      if i < H-1 and not L[i+1][j]:
        L[i+1][j] = True
        nq.append((i+1, j))
      if j < W-1 and not L[i][j+1]:
        L[i][j+1] = True
        nq.append((i, j+1))
    if nq:
      q = copy.copy(nq)
    else:
      break    
    result += 1
  print(result)
 
if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import copy
import numpy as np

H, W = map(int, input().split())
maps = [[j=="#" for j in input()] for i in range(H)]
q = deque([(i, j) for i in range(H) for j in range(W) if maps[i][j]])

count = 0
nq = deque()
while True:
  while len(q) > 0:
    x, y = q.popleft()
    if x > 0 and not maps[x-1][y]:
      maps[x-1][y] = True
      nq.append([x-1,y])
    if y > 0 and not maps[x][y-1]:
      maps[x][y-1] = True
      nq.append([x,y-1])
    if x < H-1 and not maps[x+1][y]:
      maps[x+1][y] = True
      nq.append([x+1,y])
    if y < W-1 and not maps[x][y+1]:
      maps[x][y+1] = True
      nq.append([x,y+1])
  if nq:
    q = copy.copy(nq)
  else:
      break
  count += 1
print(count)

Fixed submission:
# python には結構厳しいTLE・・・python以外のお勉強時間ないよ～( ;∀;)
# . から見た # の最大距離の方が楽ではあるが・・・
# 嫌いだけど def main も使ってみた．
from collections import deque
import copy
 
def main():
  H, W = list(map(int, input().split()))
  L = [[j=="#" for j in input()] for i in range(H)]
  q = deque([(i, j) for i in range(H) for j in range(W) if L[i][j]])
  cands = [(0, -1), (0, 1), (-1, 0), (1, 0)]
  result = 0
  while True:
    nq = deque()
    while q:
      i, j = q.popleft()
      if i > 0 and not L[i-1][j]:
        L[i-1][j] = True
        nq.append((i-1, j))
      if j > 0 and not L[i][j-1]:
        L[i][j-1] = True
        nq.append((i, j-1))
      if i < H-1 and not L[i+1][j]:
        L[i+1][j] = True
        nq.append((i+1, j))
      if j < W-1 and not L[i][j+1]:
        L[i][j+1] = True
        nq.append((i, j+1))
    if nq:
      q = copy.copy(nq)
    else:
      break    
    result += 1
  print(result)
 
if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import copy
import numpy as np

def main():
  H, W = map(int, input().split())
  maps = [[j=="#" for j in input()] for i in range(H)]
  q = deque([(i, j) for i in range(H) for j in range(W) if maps[i][j]])

  count = 0
  for i in range(H*W):
    nq = deque()
    while len(q) > 0:
      x, y = q.popleft()
      if x > 0 and not maps[x-1][y]:
        maps[x-1][y] = True
        nq.append([x-1,y])
      if y > 0 and not maps[x][y-1]:
        maps[x][y-1] = True
        nq.append([x,y-1])
      if x < H-1 and not maps[x+1][y]:
        maps[x+1][y] = True
        nq.append([x+1,y])
      if y < W-1 and not maps[x][y+1]:
        maps[x][y+1] = True
        nq.append([x,y+1])
    if nq:
      q = copy.copy(nq)
    else:
        break
    count += 1
  print(i)

if __name__ == "__main__":
  main()

Fixed submission:
# python には結構厳しいTLE・・・python以外のお勉強時間ないよ～( ;∀;)
# . から見た # の最大距離の方が楽ではあるが・・・
# 嫌いだけど def main も使ってみた．
from collections import deque
import copy
 
def main():
  H, W = list(map(int, input().split()))
  L = [[j=="#" for j in input()] for i in range(H)]
  q = deque([(i, j) for i in range(H) for j in range(W) if L[i][j]])
  cands = [(0, -1), (0, 1), (-1, 0), (1, 0)]
  result = 0
  while True:
    nq = deque()
    while q:
      i, j = q.popleft()
      if i > 0 and not L[i-1][j]:
        L[i-1][j] = True
        nq.append((i-1, j))
      if j > 0 and not L[i][j-1]:
        L[i][j-1] = True
        nq.append((i, j-1))
      if i < H-1 and not L[i+1][j]:
        L[i+1][j] = True
        nq.append((i+1, j))
      if j < W-1 and not L[i][j+1]:
        L[i][j+1] = True
        nq.append((i, j+1))
    if nq:
      q = copy.copy(nq)
    else:
      break    
    result += 1
  print(result)
 
if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import copy
import numpy as np

H, W = map(int, input().split())
maps = [[j=="#" for j in input()] for i in range(H)]
q = deque([(i, j) for i in range(H) for j in range(W) if maps[i][j]])

count = 0
for i in range(H*W):
  nq = deque()
  while len(q) > 0:
    x, y = q.popleft()
    if x > 0 and not maps[x-1][y]:
      maps[x-1][y] = True
      nq.append([x-1,y])
    if y > 0 and not maps[x][y-1]:
      maps[x][y-1] = True
      nq.append([x,y-1])
    if x < H-1 and not maps[x+1][y]:
      maps[x+1][y] = True
      nq.append([x+1,y])
    if y < W-1 and not maps[x][y+1]:
      maps[x][y+1] = True
      nq.append([x,y+1])
  if nq:
    q = copy.copy(nq)
  else:
      break
  count += 1
print(i)

Fixed submission:
# python には結構厳しいTLE・・・python以外のお勉強時間ないよ～( ;∀;)
# . から見た # の最大距離の方が楽ではあるが・・・
# 嫌いだけど def main も使ってみた．
from collections import deque
import copy
 
def main():
  H, W = list(map(int, input().split()))
  L = [[j=="#" for j in input()] for i in range(H)]
  q = deque([(i, j) for i in range(H) for j in range(W) if L[i][j]])
  cands = [(0, -1), (0, 1), (-1, 0), (1, 0)]
  result = 0
  while True:
    nq = deque()
    while q:
      i, j = q.popleft()
      if i > 0 and not L[i-1][j]:
        L[i-1][j] = True
        nq.append((i-1, j))
      if j > 0 and not L[i][j-1]:
        L[i][j-1] = True
        nq.append((i, j-1))
      if i < H-1 and not L[i+1][j]:
        L[i+1][j] = True
        nq.append((i+1, j))
      if j < W-1 and not L[i][j+1]:
        L[i][j+1] = True
        nq.append((i, j+1))
    if nq:
      q = copy.copy(nq)
    else:
      break    
    result += 1
  print(result)
 
if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import copy
import numpy as np

H, W = map(int, input().split())
maps = [[j=="#" for j in input()] for i in range(H)]
q = deque([(i, j) for i in range(H) for j in range(W) if maps[i][j]])

count = 0
for i in range(H*W):
  nq = deque()
  while len(q) > 0:
    x, y = q.popleft()
    for dx, dy in [[0,1],[0,-1],[1,0],[-1,0]]:
      nx = x+dx
      ny = y+dy
      if H > nx >= 0 and W > ny >= 0 and maps[nx][ny] != True:
        maps[nx][ny] = True
        nq.append([nx,ny])
  if nq:
    q = copy.copy(nq)
  else:
      break
  count += 1
print(i)

Fixed submission:
# python には結構厳しいTLE・・・python以外のお勉強時間ないよ～( ;∀;)
# . から見た # の最大距離の方が楽ではあるが・・・
# 嫌いだけど def main も使ってみた．
from collections import deque
import copy
 
def main():
  H, W = list(map(int, input().split()))
  L = [[j=="#" for j in input()] for i in range(H)]
  q = deque([(i, j) for i in range(H) for j in range(W) if L[i][j]])
  cands = [(0, -1), (0, 1), (-1, 0), (1, 0)]
  result = 0
  while True:
    nq = deque()
    while q:
      i, j = q.popleft()
      if i > 0 and not L[i-1][j]:
        L[i-1][j] = True
        nq.append((i-1, j))
      if j > 0 and not L[i][j-1]:
        L[i][j-1] = True
        nq.append((i, j-1))
      if i < H-1 and not L[i+1][j]:
        L[i+1][j] = True
        nq.append((i+1, j))
      if j < W-1 and not L[i][j+1]:
        L[i][j+1] = True
        nq.append((i, j+1))
    if nq:
      q = copy.copy(nq)
    else:
      break    
    result += 1
  print(result)
 
if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import copy
import numpy as np

H, W = map(int, input().split())
q = deque()
maps = []
inf = 10 ** 7
for h in range(H):
  line = list(input())
  for w in range(W):
    if line[w] == '#':
      q.append([h,w])
  maps.append([0 if x == '#' else inf for x in line])
maps = np.array(maps)

count = 0
for i in range(H*W):
  nq = deque()
  while len(q) > 0:
    x, y = q.popleft()
    for dx, dy in [[0,1],[0,-1],[1,0],[-1,0]]:
      nx = x+dx
      ny = y+dy
      if H > nx >= 0 and W > ny >= 0 and maps[nx][ny] != 0:
        maps[nx][ny] = 0
        nq.append([nx,ny])
  if nq:
    q = copy.copy(nq)
  else:
      break
  count += 1
print(i)

Fixed submission:
# python には結構厳しいTLE・・・python以外のお勉強時間ないよ～( ;∀;)
# . から見た # の最大距離の方が楽ではあるが・・・
# 嫌いだけど def main も使ってみた．
from collections import deque
import copy
 
def main():
  H, W = list(map(int, input().split()))
  L = [[j=="#" for j in input()] for i in range(H)]
  q = deque([(i, j) for i in range(H) for j in range(W) if L[i][j]])
  cands = [(0, -1), (0, 1), (-1, 0), (1, 0)]
  result = 0
  while True:
    nq = deque()
    while q:
      i, j = q.popleft()
      if i > 0 and not L[i-1][j]:
        L[i-1][j] = True
        nq.append((i-1, j))
      if j > 0 and not L[i][j-1]:
        L[i][j-1] = True
        nq.append((i, j-1))
      if i < H-1 and not L[i+1][j]:
        L[i+1][j] = True
        nq.append((i+1, j))
      if j < W-1 and not L[i][j+1]:
        L[i][j+1] = True
        nq.append((i, j+1))
    if nq:
      q = copy.copy(nq)
    else:
      break    
    result += 1
  print(result)
 
if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import copy
import numpy as np

H, W = map(int, input().split())
blacks = deque()
maps = []
inf = 10 ** 7
for h in range(H):
  line = list(input())
  for w in range(W):
    if line[w] == '#':
      blacks.append([h,w])
  maps.append([0 if x == '#' else inf for x in line])
maps = np.array(maps)

def fill():
  new_blacks = deque()
  while len(blacks) > 0:
    x, y = blacks.popleft()
    for dx, dy in [[0,1],[0,-1],[1,0],[-1,0]]:
      nx = x+dx
      ny = y+dy
      if H > nx >= 0 and W > ny >= 0 and maps[nx][ny] != 0:
        maps[nx][ny] = 0
        new_blacks.append([nx,ny])
  return new_blacks

end = False
for i in range(H*W):
  blacks = fill()
  if len(blacks) == 0:
      print(i)
      exit()

Fixed submission:
# python には結構厳しいTLE・・・python以外のお勉強時間ないよ～( ;∀;)
# . から見た # の最大距離の方が楽ではあるが・・・
# 嫌いだけど def main も使ってみた．
from collections import deque
import copy
 
def main():
  H, W = list(map(int, input().split()))
  L = [[j=="#" for j in input()] for i in range(H)]
  q = deque([(i, j) for i in range(H) for j in range(W) if L[i][j]])
  cands = [(0, -1), (0, 1), (-1, 0), (1, 0)]
  result = 0
  while True:
    nq = deque()
    while q:
      i, j = q.popleft()
      if i > 0 and not L[i-1][j]:
        L[i-1][j] = True
        nq.append((i-1, j))
      if j > 0 and not L[i][j-1]:
        L[i][j-1] = True
        nq.append((i, j-1))
      if i < H-1 and not L[i+1][j]:
        L[i+1][j] = True
        nq.append((i+1, j))
      if j < W-1 and not L[i][j+1]:
        L[i][j+1] = True
        nq.append((i, j+1))
    if nq:
      q = copy.copy(nq)
    else:
      break    
    result += 1
  print(result)
 
if __name__ == "__main__":
  main()

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

H, W = map(int, input().split())
blacks = deque()
maps = []
for h in range(H):
  line = list(input())
  for w in range(W):
    if line[w] == '#':
      blacks.append([h,w])
  maps.append(line)
copied_maps = copy.deepcopy(maps)

def fill():
  new_blacks = deque()
  while len(blacks) > 0:
    x, y = blacks.popleft()
    for dx, dy in [[0,1],[0,-1],[1,0],[-1,0]]:
      nx = x+dx
      ny = y+dy
      if H > nx >= 0 and W > ny >= 0 and copied_maps[nx][ny] != '#':
        copied_maps[nx][ny] = '#'
        new_blacks.append([nx,ny])
  return new_blacks

end = False
for i in range(H*W):
  blacks = fill()
  if len(blacks) == 0:
      print(i)
      exit()

Fixed submission:
# python には結構厳しいTLE・・・python以外のお勉強時間ないよ～( ;∀;)
# . から見た # の最大距離の方が楽ではあるが・・・
# 嫌いだけど def main も使ってみた．
from collections import deque
import copy
 
def main():
  H, W = list(map(int, input().split()))
  L = [[j=="#" for j in input()] for i in range(H)]
  q = deque([(i, j) for i in range(H) for j in range(W) if L[i][j]])
  cands = [(0, -1), (0, 1), (-1, 0), (1, 0)]
  result = 0
  while True:
    nq = deque()
    while q:
      i, j = q.popleft()
      if i > 0 and not L[i-1][j]:
        L[i-1][j] = True
        nq.append((i-1, j))
      if j > 0 and not L[i][j-1]:
        L[i][j-1] = True
        nq.append((i, j-1))
      if i < H-1 and not L[i+1][j]:
        L[i+1][j] = True
        nq.append((i+1, j))
      if j < W-1 and not L[i][j+1]:
        L[i][j+1] = True
        nq.append((i, j+1))
    if nq:
      q = copy.copy(nq)
    else:
      break    
    result += 1
  print(result)
 
if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
import copy

h, w = list(map(int, input().split()))
black_list = []
white_list = []
for i in range(h):
  for j, val in enumerate(list(input())):
    if val == "#":
      black_list.append([i,j])
    else:
      white_list.append([i,j])
max_val = 0
for white in white_list:
  min_val = w*h
  for black in black_list:
    diff = abs(white[0]-black[0]) + abs(white[1]-black[1])
    if diff < min_val:
      min_val = diff
  if max_val < min_val:
    max_val = min_val
print(max_val)

Fixed submission:
# python には結構厳しいTLE・・・python以外のお勉強時間ないよ～( ;∀;)
# . から見た # の最大距離の方が楽ではあるが・・・
# 嫌いだけど def main も使ってみた．
from collections import deque
import copy
 
def main():
  H, W = list(map(int, input().split()))
  L = [[j=="#" for j in input()] for i in range(H)]
  q = deque([(i, j) for i in range(H) for j in range(W) if L[i][j]])
  cands = [(0, -1), (0, 1), (-1, 0), (1, 0)]
  result = 0
  while True:
    nq = deque()
    while q:
      i, j = q.popleft()
      if i > 0 and not L[i-1][j]:
        L[i-1][j] = True
        nq.append((i-1, j))
      if j > 0 and not L[i][j-1]:
        L[i][j-1] = True
        nq.append((i, j-1))
      if i < H-1 and not L[i+1][j]:
        L[i+1][j] = True
        nq.append((i+1, j))
      if j < W-1 and not L[i][j+1]:
        L[i][j+1] = True
        nq.append((i, j+1))
    if nq:
      q = copy.copy(nq)
    else:
      break    
    result += 1
  print(result)
 
if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
import copy

h, w = list(map(int, input().split()))
black_list = []
for i in range(h):
  for j, val in enumerate(list(input())):
    if val == "#":
      black_list.append([i,j])
max_val = 0
for i in range(h):
  for j in range(w):
    min_val = h*w
    for point in black_list:
      diff = abs(i-point[0]) + abs(j-point[1])
      if diff < min_val:
        min_val = diff
    if max_val < min_val:
      max_val = min_val
print(max_val)

Fixed submission:
# python には結構厳しいTLE・・・python以外のお勉強時間ないよ～( ;∀;)
# . から見た # の最大距離の方が楽ではあるが・・・
# 嫌いだけど def main も使ってみた．
from collections import deque
import copy
 
def main():
  H, W = list(map(int, input().split()))
  L = [[j=="#" for j in input()] for i in range(H)]
  q = deque([(i, j) for i in range(H) for j in range(W) if L[i][j]])
  cands = [(0, -1), (0, 1), (-1, 0), (1, 0)]
  result = 0
  while True:
    nq = deque()
    while q:
      i, j = q.popleft()
      if i > 0 and not L[i-1][j]:
        L[i-1][j] = True
        nq.append((i-1, j))
      if j > 0 and not L[i][j-1]:
        L[i][j-1] = True
        nq.append((i, j-1))
      if i < H-1 and not L[i+1][j]:
        L[i+1][j] = True
        nq.append((i+1, j))
      if j < W-1 and not L[i][j+1]:
        L[i][j+1] = True
        nq.append((i, j+1))
    if nq:
      q = copy.copy(nq)
    else:
      break    
    result += 1
  print(result)
 
if __name__ == "__main__":
  main()