Problem p02855 (python)

Fixed submission:
H, W, K = map(int,input().split())
S = list(list(input())for i in range(H))
cake = [[0]*W for i in range(H)]

queue = []
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            queue.append([i,j])
            cake[i][j] = -1
for i in range(len(queue)):
    h,w = queue[i]
    U,D,L,R = 0,0,0,0
    while L < w:
        if cake[h][w-L-1]:
            break
        L += 1
    while R+w < W-1:
        if cake[h][w+R+1]:
            break
        R += 1
    while U < h:
        flag = False
        for k in range(w-L,w+R+1):
            if cake[h-U-1][k]:
                flag = True
        if flag:
            break
        U += 1
    while D+h < H-1:
        flag = False
        for k in range(w-L,w+R+1):
            if cake[h+D+1][k] != 0:
                flag = True
                break
        if flag:
            break
        D += 1
    for x in range(h-U,h+D+1):
        for y in range(w-L,w+R+1):
            cake[x][y] = i+1

for i in cake:
    print(*i)

Buggy submission (verdict: Runtime Error):
H, W, K = map(int,input().split())
S = list(list(input())for i in range(H))
cake = [[0]*W for i in range(H)]

queue = []
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            queue.append([i,j])
            cake[i][j] = -1
for i in range(K):
    h,w = queue[i]
    U,D,L,R = 0,0,0,0
    while U < h:
        if cake[h-U-1][w]:
            break
        U += 1
    while D+h < H-1:
        if cake[h+D+1][w]:
            break
        D += 1
    while L < w:
        flag = False
        for k in range(h-U,h+D+1):
            if cake[k][w-L-1]:
                flag = True
        if flag:
            break
        L += 1
    while R + w < W-1:
        flag = False
        for k in range(h-U, h+D+1):
            if cake[k][w+R+1]:
                flag = True
        if flag:
            break
        R += 1
    for x in range(h-U,h+D+1):
        for y in range(w-L,w+R+1):
            cake[x][y] = i+1

for i in cake:
    if min(i) == 0:
        a = 1/0
    print(*i)

Buggy submission (verdict: Runtime Error):
import numpy as np
W, H, K = map(int,input().split())
S = list(list(input())for i in range(H))
cake = [[0]*W for i in range(H)]
cake = np.array(cake).T
queue = []
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            queue.append([i,j])
            cake[i][j] = -1
for i in range(len(queue)):
    h,w = queue[i]
    U,D,L,R = 0,0,0,0
    while U < h:
        if cake[h-U-1][w] != 0:
            break
        U += 1
    while D + h < H-1:
        if cake[h+D+1][w] != 0:
            break
        D += 1
    while L < w:
        flag = False
        for k in range(h-U,h+D+1):
            if cake[k][w-L-1] != 0:
                flag = True
        if flag:
            break
        L += 1
    while R + w < W-1:
        flag = False
        for k in range(h-U,h+D+1):
            if cake[k][w+R+1] != 0:
                flag = True
        if flag:
            break
        R += 1
    for x in range(h-U,h+D+1):
        for y in range(w-L,w+R+1):
            cake[x][y] = i+1

for i in cake:
    print(*i)

Buggy submission (verdict: Runtime Error):
H, W, K = map(int,input().split())
S = list(list(input())for i in range(H))
cake = [[0]*W for i in range(H)]

queue = []
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            queue.append([i,j])
            cake[i][j] = -1
for i in range(len(queue)):
    h,w = queue[i]
    U,D,L,R = 0,0,0,0
    while L < w:
        if cake[h][w-L-1]:
            break
        L += 1
    while R < W-w-1:
        if cake[h][w+R+1]:
            break
        R += 1
    while U < h:
        flag = False
        for k in range(w-L,w+R+1):
            if cake[h-U-1][k]:
                flag = True
        if flag:
            break
        U += 1
    while D < H-h-1:
        for k in range(w-L,w+R+1):
            if cake[h+D+1][k]:
                flag = True
        if flag:
            break
    for x in range(h-U,h+D+1):
        for y in range(w-L,w+R+1):
            cake[x][y] = i+1

for i in cake:
    print(*i)

Buggy submission (verdict: Runtime Error):
H, W, K = map(int,input().split())
S = list(list(input())for i in range(H))
cake = [[0]*W for i in range(H)]
ans = [[0]*W for i in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            cake[i][j] = 1
i = 0
a = 0
queue = []
while i < H:
    if max(cake[i]) == 0:
        ans[i] = ans[i-1]
        i += 1
        continue
    first = cake[i][0] != 1
    for j in range(W):
        if j == 0:
            ans[i][j] = ans[i-1][-1] + 1
        if cake[i][j] == 1:
            if first == True:
                first = False
                ans[i][j] = ans[i][j-1]
            else:
                ans[i][j] = ans[i][j-1]+1
        elif j != 0:
            ans[i][j] = ans[i][j-1]
    i += 1
i = 0
while ans[i][0] != 1:
    ans[i] = ans[i+1]
    i += 1
for i in ans:
    print(*i)

Buggy submission (verdict: Runtime Error):
H, W, K = map(int,input().split())
S = list(list(input())for i in range(H))
cake = [[0]*W for i in range(H)]

queue = []
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            queue.append([i,j])
            cake[i][j] = -1
for i in range(len(queue)):
    h,w = queue[i]
    cake[h][w] = i+1
    U,D,L,R = 0,0,0,0
    while U < h:
        if cake[h-U-1][w] != 0:
            break
        U += 1
    while D + h < H-1:
        if cake[h+D+1][w] != 0:
            break
        D += 1
    while L < w:
        flag = False
        for k in range(h-U,h+D+1):
            if cake[k][w-L-1] != 0:
                flag = True
                break
        if flag:
            break
        L += 1
    while R + w < W-1:
        flag = False
        for k in range(h-U,h+D+1):
            if cake[k][w+R+1] != 0:
                flag = True
                break
        if flag:
            break
        R += 1
    for x in range(h-U,h+D+1):
        for y in range(w-L,w+R+1):
            cake[x][y] = i+1
for i in cake:
    if min(i)  <= 0:
        print(1/0)
    print(*i)