Problem p03053 (python)

Fixed submission:
H,W = map( int, input().split() )

x = []

for _ in range(H):
    row = list( input() )
    x.append(row)

blacks = []
count = 0

for i in range(H):
    for j in range(W):
        a = x[i][j]
        if a == '#':
            count += 1
            blacks.append((i,j))

result = 0
DIRS = [(0,1),(0,-1),(1,0),(-1,0)]

while count < H*W:
    result += 1
    new_blacks = []
    for black in blacks:
        for dir in DIRS:
            i = black[0]+dir[0]
            j = black[1]+dir[1]
            if i < 0 or i >= H:
                continue
            if j < 0 or j >= W:
                continue
            if x[i][j] == '.':
                new_blacks.append((i,j))
                x[i][j] = '#'
                count += 1
    blacks = new_blacks

print(result)

Buggy submission (verdict: Runtime Error):
H,W = map( int, input().split() )

x = []

for _ in range(H):
    row = list( input() )
    x.append(row)

blacks = []
count = 0

for i in range(H):
    for j in range(W):
        a = x[i][j]
        if a == '#':
            count += 1
            blacks.append((i,j))

result = 0

DIRS = [(0,1),(0,-1),(1,0),(-1,0)]

while count < H*W:
    result += 1
    new_blacks = []
    for black in blacks:
        for dir in DIRS:
            i = black[0]+dir[0]
            j = black[1]+dir[1]
            if i < 0 or i >= H:
                continue
            if j < 0 or j >= H:
                continue
            if x[i][j] == '.':
                new_blacks.append((i,j))
                x[i][j] = '#'
                count += 1
    blacks = new_blacks

print(result)

Buggy submission (verdict: Runtime Error):
H,W = map( str, input().split() )

x = []

for _ in range(H):
    x.append = list(input())

blacks = []
count = 0

for i in range(H):
    for j in range(W):
        a = x[i][j]
        if a == '#':
            count += 1
            blacks.append((i,j))

result = 0

DIRS = [(0,1),(0,-1),(1,0),(-1,0)]

while count < H*W:
    result += 1
    new_blacks = []
    for black in blacks:
        for dir in DIRS:
            i = black[0]+dir[0]
            j = black[1]+dir[1]
            if i < 0 or i >= H:
                continue
            if j < 0 or j >= H:
                continue
            if x[i][j] == '.':
                new_blacks.append((i,j))
                x[i][j] = '#'
                count += 1
    blacks = new_blacks

print(result)

Buggy submission (verdict: Runtime Error):
h,w = map( str, input().split() )

x = []

for _ in range(h):
    x.append = list(input())

blacks = []
count = 0

for i in range(H):
    for j in range(W):
        a = A[i][j]
        if a == '#':
            count += 1
            blacks.append((i,j))

result = 0

DIRS = [(0,1),(0,-1),(1,0),(-1,0)]

while count < H*W:
    result += 1
    new_blacks = []
    for black in blacks:
        for dir in DIRS:
            i = black[0]+dir[0]
            j = black[1]+dir[1]
            if i < 0 or i >= H:
                continue
            if j < 0 or j >= H:
                continue
            if A[i][j] == '.':
                new_blacks.append((i,j))
                A[i][j] = '#'
                count += 1
    blacks = new_blacks

print(result)

Buggy submission (verdict: Runtime Error):
h,w = map( str, input().split() )

x = []

for _ in range(h):
    x.append = list(input())

blacks = []
count = 0

for i in range(H):
    for j in range(W):
        a = A[i][j]
        if a == '#':
            count += 1
            blacks.append((i,j))

result = 0

DIRS = [(0,1),(0,-1),(1,0),(-1,0)]

while count < H*W:
    result += 1
    new_blacks = []
    for black in blacks:
        for dir in DIRS:
            i = black[0]+dir[0]
            j = black[1]+dir[1]
            if i < 0 or i >= H:
                continue
            if j < 0 or j >= H:
                continue
            if A[i][j] == '.':
                new_blacks.append((i,j))
                A[i][j] = '#'
                count += 1
    blacks = new_blacks

print(result)