Buggy python submission (verdict: Time Limit Exceeded):
import copy
from collections import deque
def main():
  H, W = map(int, input().split())
  M = [['#' == x for x in input()] for _ in range(H)]

  black = deque([(i, j) for i in range(H) for j in range(W) if M[i][j]])

  ans = 0
  while True:
    ans += 1
    next_black = deque()
    while black:
      bi, bj = black.popleft()
      if bi - 1 >= 0 and not M[bi - 1][bj]:
        M[bi - 1][bj] = True
        next_black.append((bi - 1, bj))
      if bj - 1 >= 0 and not M[bi][bj - 1]:
        M[bi][bj - 1] = True
        next_black.append((bi, bj - 1))
      if bi + 1 < H and not M[bi + 1][bj]:
        M[bi + 1][bj] = True
        next_black.append((bi + 1, bj))
      if bj + 1 < W and not M[bi][bj + 1]:
        M[bi][bj + 1] = True
        next_black.append((bi, bj + 1))
    if next_black:
       black = copy.copy(next_black)
    else:
       break
  print(ans - 1)
  
if __name__ == "__main__":
  main()


Fixed submission:
from collections import deque
import copy
 
def main():
    h, w = map(int, input().split())
    a = [[j == "#" for j in input()] for _ in range(h)]
 
 
    que = deque([(i, j) for i in range(h) for j in range(w) if a[i][j]])
 
    count = 0
    while True:
        count += 1
        nque = deque()
        while que:
            y, x = que.popleft()
            if x > 0 and not a[y][x-1]:
                a[y][x-1] = True
                nque.append((y,x-1))
            if x < w-1 and not a[y][x+1]:
                a[y][x+1] = True
                nque.append((y,x+1))
            if y > 0 and not a[y-1][x]:
                a[y-1][x] = True
                nque.append((y-1,x))
            if y < h-1 and not a[y+1][x]:
                a[y+1][x] = True
                nque.append((y+1,x))
 
        if nque:
            que = copy.copy(nque)
        else:
            break
 
    print(count - 1)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import copy
from collections import deque
H, W = map(int, input().split())
M = [['#' == x for x in input()] for _ in range(H)]

black = deque([(i, j) for i in range(H) for j in range(W) if M[i][j]])

ans = 0
while True:
  ans += 1
  next_black = deque()
  while black:
    bi, bj = black.popleft()
    if bi - 1 >= 0 and not M[bi - 1][bj]:
      M[bi - 1][bj] = True
      next_black.append((bi - 1, bj))
    if bj - 1 >= 0 and not M[bi][bj - 1]:
      M[bi][bj - 1] = True
      next_black.append((bi, bj - 1))
    if bi + 1 < H and not M[bi + 1][bj]:
      M[bi + 1][bj] = True
      next_black.append((bi + 1, bj))
    if bj + 1 < W and not M[bi][bj + 1]:
      M[bi][bj + 1] = True
      next_black.append((bi, bj + 1))
  if next_black:
     black = copy.copy(next_black)
  else:
     break
print(ans - 1)


  

Fixed submission:
from collections import deque
import copy
 
def main():
    h, w = map(int, input().split())
    a = [[j == "#" for j in input()] for _ in range(h)]
 
 
    que = deque([(i, j) for i in range(h) for j in range(w) if a[i][j]])
 
    count = 0
    while True:
        count += 1
        nque = deque()
        while que:
            y, x = que.popleft()
            if x > 0 and not a[y][x-1]:
                a[y][x-1] = True
                nque.append((y,x-1))
            if x < w-1 and not a[y][x+1]:
                a[y][x+1] = True
                nque.append((y,x+1))
            if y > 0 and not a[y-1][x]:
                a[y-1][x] = True
                nque.append((y-1,x))
            if y < h-1 and not a[y+1][x]:
                a[y+1][x] = True
                nque.append((y+1,x))
 
        if nque:
            que = copy.copy(nque)
        else:
            break
 
    print(count - 1)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import copy
from collections import deque
H, W = map(int, input().split())
M = [['#' == x for x in input()] for _ in range(H)]

black = deque()
for i in range(H):
  for j in range(W):
    if M[i][j]:
      black.append((i, j))

ans = 0
while True:
  ans += 1
  next_black = deque()
  while black:
    bi, bj = black.popleft()
    if bi - 1 >= 0 and not M[bi - 1][bj]:
      M[bi - 1][bj] = True
      next_black.append((bi - 1, bj))
    if bj - 1 >= 0 and not M[bi][bj - 1]:
      M[bi][bj - 1] = True
      next_black.append((bi, bj - 1))
    if bi + 1 < H and not M[bi + 1][bj]:
      M[bi + 1][bj] = True
      next_black.append((bi + 1, bj))
    if bj + 1 < W and not M[bi][bj + 1]:
      M[bi][bj + 1] = True
      next_black.append((bi, bj + 1))
  if next_black:
     black = copy.copy(next_black)
  else:
     break
print(ans - 1)


Fixed submission:
from collections import deque
import copy
 
def main():
    h, w = map(int, input().split())
    a = [[j == "#" for j in input()] for _ in range(h)]
 
 
    que = deque([(i, j) for i in range(h) for j in range(w) if a[i][j]])
 
    count = 0
    while True:
        count += 1
        nque = deque()
        while que:
            y, x = que.popleft()
            if x > 0 and not a[y][x-1]:
                a[y][x-1] = True
                nque.append((y,x-1))
            if x < w-1 and not a[y][x+1]:
                a[y][x+1] = True
                nque.append((y,x+1))
            if y > 0 and not a[y-1][x]:
                a[y-1][x] = True
                nque.append((y-1,x))
            if y < h-1 and not a[y+1][x]:
                a[y+1][x] = True
                nque.append((y+1,x))
 
        if nque:
            que = copy.copy(nque)
        else:
            break
 
    print(count - 1)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import copy
from collections import deque
H, W = map(int, input().split())
M = [list(input()) for _ in range(H)]

black = deque()
for i in range(H):
  for j in range(W):
    if M[i][j] == '#':
      black.append((i, j))

ans = 0
while True:
  ans += 1
  next_black = deque()
  while black:
    bi, bj = black.popleft()
    if bi - 1 >= 0 and M[bi - 1][bj] == '.':
      M[bi - 1][bj] = '#'
      next_black.append((bi - 1, bj))
    if bj - 1 >= 0 and M[bi][bj - 1] == '.':
      M[bi][bj - 1] = '#'
      next_black.append((bi, bj - 1))
    if bi + 1 < H and M[bi + 1][bj] == '.':
      M[bi + 1][bj] = '#'
      next_black.append((bi + 1, bj))
    if bj + 1 < W and M[bi][bj + 1] == '.':
      M[bi][bj + 1] = '#'
      next_black.append((bi, bj + 1))
  if next_black:
     black = copy.copy(next_black)
  else:
     break
print(ans - 1)


Fixed submission:
from collections import deque
import copy
 
def main():
    h, w = map(int, input().split())
    a = [[j == "#" for j in input()] for _ in range(h)]
 
 
    que = deque([(i, j) for i in range(h) for j in range(w) if a[i][j]])
 
    count = 0
    while True:
        count += 1
        nque = deque()
        while que:
            y, x = que.popleft()
            if x > 0 and not a[y][x-1]:
                a[y][x-1] = True
                nque.append((y,x-1))
            if x < w-1 and not a[y][x+1]:
                a[y][x+1] = True
                nque.append((y,x+1))
            if y > 0 and not a[y-1][x]:
                a[y-1][x] = True
                nque.append((y-1,x))
            if y < h-1 and not a[y+1][x]:
                a[y+1][x] = True
                nque.append((y+1,x))
 
        if nque:
            que = copy.copy(nque)
        else:
            break
 
    print(count - 1)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import copy
from collections import deque
H, W = map(int, input().split())
M = [list(input()) for _ in range(H)]

black = deque()
for i in range(H):
  for j in range(W):
    if M[i][j] == '#':
      black.append((i, j))

ans = 0
while True:
  ans += 1
  next_black = deque()
  while black:
    bi, bj = black.popleft()
    for i, j in [(bi - 1, bj), (bi + 1, bj), (bi, bj - 1), (bi, bj + 1)]:
      if i >= 0 and i < H and j >= 0 and j < W:
        if M[i][j] == '.':
          M[i][j] = '#'
          next_black.append((i, j))
  if next_black:
     black = copy.copy(next_black)
  else:
     break
print(ans - 1)

Fixed submission:
from collections import deque
import copy
 
def main():
    h, w = map(int, input().split())
    a = [[j == "#" for j in input()] for _ in range(h)]
 
 
    que = deque([(i, j) for i in range(h) for j in range(w) if a[i][j]])
 
    count = 0
    while True:
        count += 1
        nque = deque()
        while que:
            y, x = que.popleft()
            if x > 0 and not a[y][x-1]:
                a[y][x-1] = True
                nque.append((y,x-1))
            if x < w-1 and not a[y][x+1]:
                a[y][x+1] = True
                nque.append((y,x+1))
            if y > 0 and not a[y-1][x]:
                a[y-1][x] = True
                nque.append((y-1,x))
            if y < h-1 and not a[y+1][x]:
                a[y+1][x] = True
                nque.append((y+1,x))
 
        if nque:
            que = copy.copy(nque)
        else:
            break
 
    print(count - 1)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import copy
H, W = map(int, input().split())
M = [list(input()) for _ in range(H)]

black = []
for i in range(H):
  for j in range(W):
    if M[i][j] == '#':
      black.append((i, j))
ans = 0
while True:
  ans += 1
  next_black = []
  while black:
    bi, bj = black.pop(0)
    for i, j in [(bi - 1, bj), (bi + 1, bj), (bi, bj - 1), (bi, bj + 1)]:
      if i >= 0 and i < H and j >= 0 and j < W:
        if M[i][j] == '.':
          M[i][j] = '#'
          next_black.append((i, j))
  if next_black:
     black = copy.copy(next_black)
  else:
     break
print(ans - 1)

Fixed submission:
from collections import deque
import copy
 
def main():
    h, w = map(int, input().split())
    a = [[j == "#" for j in input()] for _ in range(h)]
 
 
    que = deque([(i, j) for i in range(h) for j in range(w) if a[i][j]])
 
    count = 0
    while True:
        count += 1
        nque = deque()
        while que:
            y, x = que.popleft()
            if x > 0 and not a[y][x-1]:
                a[y][x-1] = True
                nque.append((y,x-1))
            if x < w-1 and not a[y][x+1]:
                a[y][x+1] = True
                nque.append((y,x+1))
            if y > 0 and not a[y-1][x]:
                a[y-1][x] = True
                nque.append((y-1,x))
            if y < h-1 and not a[y+1][x]:
                a[y+1][x] = True
                nque.append((y+1,x))
 
        if nque:
            que = copy.copy(nque)
        else:
            break
 
    print(count - 1)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
M = [list(input()) for _ in range(H)]

black = []
distance = [[-1 for _ in range(H)] for _ in range(W)]
for i in range(H):
  for j in range(W):
    if M[i][j] == '#':
      black.append((i, j))
      distance[i][j] = 0
      
while black:
  bi, bj = black.pop(0)
  for i, j in [(bi - 1, bj), (bi + 1, bj), (bi, bj - 1), (bi, bj + 1)]:
    if i >= 0 and i < H and j >= 0 and j < W:
      if M[i][j] == '.' and distance[i][j] == -1:
        M[i][j] = '#'
        black.append((i, j))
        distance[i][j] = distance[bi][bj] + 1
print(max([x for d in distance for x in d]))

Fixed submission:
from collections import deque
import copy
 
def main():
    h, w = map(int, input().split())
    a = [[j == "#" for j in input()] for _ in range(h)]
 
 
    que = deque([(i, j) for i in range(h) for j in range(w) if a[i][j]])
 
    count = 0
    while True:
        count += 1
        nque = deque()
        while que:
            y, x = que.popleft()
            if x > 0 and not a[y][x-1]:
                a[y][x-1] = True
                nque.append((y,x-1))
            if x < w-1 and not a[y][x+1]:
                a[y][x+1] = True
                nque.append((y,x+1))
            if y > 0 and not a[y-1][x]:
                a[y-1][x] = True
                nque.append((y-1,x))
            if y < h-1 and not a[y+1][x]:
                a[y+1][x] = True
                nque.append((y+1,x))
 
        if nque:
            que = copy.copy(nque)
        else:
            break
 
    print(count - 1)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
M = [list(input()) for _ in range(H)]

black = []
distance = [[-1 for _ in range(H)] for _ in range(W)]
for i in range(H):
  for j in range(W):
    if M[i][j] == '#':
      black.append((i, j))
      distance[i][j] = 0
      
while black:
  bi, bj = black.pop(0)
  for i, j in [(bi - 1, bj), (bi + 1, bj), (bi, bj - 1), (bi, bj + 1)]:
    if i >= 0 and i < H and j >= 0 and j < W:
      if M[i][j] == '.' and distance[i][j] == -1:
        M[i][j] = '#'
        black.append((i, j))
        distance[i][j] = distance[bi][bj] + 1
print(max([max(d) for d in distance]))

Fixed submission:
from collections import deque
import copy
 
def main():
    h, w = map(int, input().split())
    a = [[j == "#" for j in input()] for _ in range(h)]
 
 
    que = deque([(i, j) for i in range(h) for j in range(w) if a[i][j]])
 
    count = 0
    while True:
        count += 1
        nque = deque()
        while que:
            y, x = que.popleft()
            if x > 0 and not a[y][x-1]:
                a[y][x-1] = True
                nque.append((y,x-1))
            if x < w-1 and not a[y][x+1]:
                a[y][x+1] = True
                nque.append((y,x+1))
            if y > 0 and not a[y-1][x]:
                a[y-1][x] = True
                nque.append((y-1,x))
            if y < h-1 and not a[y+1][x]:
                a[y+1][x] = True
                nque.append((y+1,x))
 
        if nque:
            que = copy.copy(nque)
        else:
            break
 
    print(count - 1)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
M = [list(input()) for _ in range(H)]

black = []
for i in range(H):
  for j in range(W):
    if M[i][j] == '#':
      black.append((i, j))
      
ans = 0

while any('.' in m for m in M):
  ans += 1
  next_black = []
  while black:
    bi, bj = black.pop(0)
    for i, j in [(bi - 1, bj), (bi + 1, bj), (bi, bj - 1), (bi, bj + 1)]:
      if i >= 0 and i < H and j >= 0 and j < W:
        if M[i][j] == '.':
          M[i][j] = '#'
          next_black.append((i, j))
  black = next_black
  
print(ans)



Fixed submission:
from collections import deque
import copy
 
def main():
    h, w = map(int, input().split())
    a = [[j == "#" for j in input()] for _ in range(h)]
 
 
    que = deque([(i, j) for i in range(h) for j in range(w) if a[i][j]])
 
    count = 0
    while True:
        count += 1
        nque = deque()
        while que:
            y, x = que.popleft()
            if x > 0 and not a[y][x-1]:
                a[y][x-1] = True
                nque.append((y,x-1))
            if x < w-1 and not a[y][x+1]:
                a[y][x+1] = True
                nque.append((y,x+1))
            if y > 0 and not a[y-1][x]:
                a[y-1][x] = True
                nque.append((y-1,x))
            if y < h-1 and not a[y+1][x]:
                a[y+1][x] = True
                nque.append((y+1,x))
 
        if nque:
            que = copy.copy(nque)
        else:
            break
 
    print(count - 1)

if __name__ == "__main__":
    main()