Problem p03053 (python)

Fixed submission:
# -*- coding: utf-8 -*-
# 18:01 -> 18:36 (give up. TLE)
from collections import deque

dx = [0,1,0,-1]
dy = [1,0,-1,0]

H, W = map(int, input().split())

A = []
black_deque = deque()

for i in range(H):
    A.append(list(input()))
    black_deque.extend([(i,j) for j in range(W) if A[i][j] == '#'])

if len(black_deque) == H*W:
    print(0)
    exit(0)

for x,y in black_deque:
    A[x][y] = 0

while len(black_deque) != 0:
    x,y = black_deque.popleft()
    depth = A[x][y]
    for k in range(4):
        new_x = x+dx[k]
        new_y = y+dy[k]
        if 0 <= new_x < H and \
           0 <= new_y < W and \
           A[new_x][new_y] == '.':
            black_deque.append((new_x, new_y))
            A[new_x][new_y] = depth+1

print(depth)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 18:01 -> 18:36 (give up. TLE)
from collections import deque

dx = [0,1,0,-1]
dy = [1,0,-1,0]

H, W = map(int, input().split())

A = []
black_deque = deque()

for i in range(H):
    A.append(list(input()))
    black_deque.extend([(i,j) for j in range(W) if A[i][j] == '#'])

for x,y in black_deque:
    A[x][y] = 0

n_white = H*W-len(black_deque)
while len(black_deque) != 0:
    x,y = black_deque.popleft()
    depth = A[x][y]
    tansaku = [(x+dx[k], y+dy[k]) for k in range(4)
        if 0 <= x+dx[k] < H and
           0 <= y+dy[k] < W and
           A[x+dx[k]][y+dy[k]] == '.'
    ]
    for new_x,new_y in tansaku:
        black_deque.append((new_x, new_y))
        n_while -= 1
        A[new_x][new_y] = depth+1
        if n_white == 0:
            print(depth+1)
            exit(0)

print(depth)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 18:01 -> 18:36 (give up. TLE)
from collections import deque

dx = [0,1,0,-1]
dy = [1,0,-1,0]

H, W = map(int, input().split())

A = []
black_deque = deque()

for i in range(H):
    A.append(list(input()))
    black_deque.extend([(i,j) for j in range(W) if A[i][j] == '#'])

for x,y in black_deque:
    A[x][y] = 0

print(len(black_deque))

while len(black_deque) != 0:
    x,y = black_deque.popleft()
    depth = A[x][y]
    tansaku = [x+dx[k], y+dy[k] for k in range(4)
        if 0 <= new_x < H and
           0 <= new_y < W and
           A[new_x][new_y] == '.'
    ]
    for new_x,new_y in tansaku:
        black_deque.append((new_x, new_y))
        A[new_x][new_y] = depth+1

print(depth)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 18:01 -> 
from collections import deque

dx = [0,1,0,-1]
dy = [1,0,-1,0]

H, W = map(int, input().split())

A = []
first_black = []

for i in range(H):
    A.append(list(input()))
    first_black.extend([(i,j) for j in range(W) if A[i][j] == '#'])

for x,y in first_black:
    A[x][y] = 0

black_deque = deque()
black_deque.extend(first_black)

max_depth = 0
while len(black_deque) != 0:
    x,y = black_deque.popleft()
    depth = A[x][y]
    max_depth = max(max_depth, depth)
    for k in range(4):
        new_x = x+dx[k]
        new_y = y+dy[k]
        if A[new_x][new_y] == '.' and \
           0 <= new_x < H and \
           0 <= new_y < W:
            black_deque.append((new_x, new_y))
            A[new_x][new_y] = depth+1

print(depth)