Problem p02855 (python)

Fixed submission:
H, W, K = map(int, input().split())
c = [list(input()) for _ in range(H)]

index = 0
for i in range(H):
    cnt = 0
    for j in range(W):
        if c[i][j] == '#':
            index += 1
            cnt = index
            c[i][j] = cnt
        if c[i][j] == '.' and cnt != 0:
            c[i][j] = cnt

for i in range(H):
    for j in reversed(range(W - 1)):
        if c[i][j] == '.':
            c[i][j] = c[i][j + 1]

for i in range(H - 1):
    for j in range(W):
        if c[i][j] != '.' and c[i + 1][j] == '.':
            c[i + 1][j] = c[i][j]

for i in reversed(range(1, H)):
    for j in range(W):
        if c[i][j] != '.' and c[i - 1][j] == '.':
            c[i - 1][j] = c[i][j]


for i in range(H):
    for j in range(W):
        if j != W - 1:
            print(c[i][j], end=' ')
        else:
            print(c[i][j])

Buggy submission (verdict: Runtime Error):
import bisect
import copy
H, W, K = map(int, input().split())
c = [list(input()) for _ in range(H)]

ilst = []
index = 1
for i in range(H):
    for j in range(W):
        if c[i][j] == '#':
            c[i][j] = index
            index += 1
            ilst.append([i, j])

nlst = []
for i in range(K - 1):
    if ilst[i][0] == ilst[i + 1][0]:
        cindex = 0
        if c[ilst[i][0]][0] != '.':
            cindex = ilst[i][1]

        for j in range(cindex, ilst[i + 1][1]):
            c[ilst[i][0]][j] = i + 1
        for j in range(ilst[i + 1][1], W):
            c[ilst[i + 1][0]][j] = i + 2
    else:
        if c[ilst[i][0]][0] == '.':
            for j in range(W):
                c[ilst[i][0]][j] = i + 1
    if c[ilst[i][0]] != '.':
        if nlst == []:
            nlst.append(ilst[i][0])
        elif nlst[-1] != ilst[i][0]:
            nlst.append(ilst[i][0])

for i in range(H):
    if c[i][0] == '.':
        copyi = bisect.bisect_left(nlst, i)
        if copyi < len(nlst):
            c[i] = copy.copy(c[nlst[copyi]])
        else:
            c[i] = copy.copy(c[nlst[len(nlst) - 1]])

for i in range(H):
    for j in range(W):
        if j != W - 1:
            print(c[i][j], end=' ')
        else:
            print(c[i][j])

Buggy submission (verdict: Runtime Error):
import bisect
import copy
H, W, K = map(int, input().split())
c = [list(input()) for _ in range(H)]

ilst = []
index = 1
for i in range(H):
    for j in range(W):
        if c[i][j] == '#':
            c[i][j] = index
            index += 1
            ilst.append([i, j])

nlst = []
for i in range(K - 1):
    if ilst[i][0] == ilst[i + 1][0]:
        cindex = 0
        if c[ilst[i][0]][0] != '.':
            cindex = ilst[i][1]

        for j in range(cindex, ilst[i + 1][1]):
            c[ilst[i][0]][j] = i + 1
        for j in range(ilst[i + 1][1], W):
            c[ilst[i + 1][0]][j] = i + 2
    else:
        if c[ilst[i][0]][0] == '.':
            for j in range(W):
                c[ilst[i][0]][j] = i + 1
    if c[ilst[i][0]] != '.':
        if nlst == []:
            nlst.append(ilst[i][0])
        elif nlst[-1] != ilst[i][0]:
            nlst.append(ilst[i][0])

for i in range(H):
    if c[i][0] == '.':
        copyi = bisect.bisect_left(nlst, i)
        if copyi <= len(nlst) - 1:
            c[i] = copy.copy(c[nlst[copyi]])
        else:
            c[i] = copy.copy(c[nlst[copyi - 1]])

for i in range(H):
    for j in range(W):
        if j != W - 1:
            print(c[i][j], end=' ')
        else:
            print(c[i][j])

Buggy submission (verdict: Runtime Error):
import bisect
import copy
H, W, K = map(int, input().split())
c = [list(input()) for _ in range(H)]
moveRow = [0, 1, -1, 0]
moveCol = [1, 0, 0, -1]
ilst = []
index = 1
for i in range(H):
    for j in range(W):
        if c[i][j] == '#':
            c[i][j] = index
            index += 1
            ilst.append([i, j])

nlst = []
for i in range(K - 1):
    if ilst[i][0] == ilst[i + 1][0]:
        cindex = 0
        if c[ilst[i][0]][0] != '.':
            cindex = ilst[i][1]

        for j in range(cindex, ilst[i + 1][1]):
            c[ilst[i][0]][j] = i + 1
        for j in range(ilst[i + 1][1], W):
            c[ilst[i + 1][0]][j] = i + 2
    else:
        if c[ilst[i][0]][0] == '.':
            for j in range(W):
                c[ilst[i][0]][j] = i + 1
    if c[ilst[i][0]] != '.':
        if nlst == []:
            nlst.append(ilst[i][0])
        elif nlst[-1] != ilst[i][0]:
            nlst.append(ilst[i][0])
copyi = 0
for i in range(H):
    if c[i][0] == '.':
        copyi = bisect.bisect_left(nlst, i)
        if copyi <= len(nlst) - 1:
            c[i] = copy.copy(c[nlst[copyi]])
        else:
            c[i] = copy.copy(c[nlst[copyi - 1]])

for i in range(H):
    for j in range(W):
        if j != W - 1:
            print(c[i][j], end=' ')
        else:
            print(c[i][j])

Buggy submission (verdict: Runtime Error):
import bisect
import copy
H, W, K = map(int, input().split())
c = [list(input()) for _ in range(H)]
moveRow = [0, 1, -1, 0]
moveCol = [1, 0, 0, -1]
ilst = []
index = 1
for i in range(H):
    for j in range(W):
        if c[i][j] == '#':
            c[i][j] = index
            index += 1
            ilst.append([i, j])

nlst = []
for i in range(K - 1):
    if ilst[i][0] == ilst[i + 1][0]:
        cindex = 0
        if c[ilst[i][0]][0] != '.':
            cindex = ilst[i][1]

        for j in range(cindex, ilst[i + 1][1]):
            c[ilst[i][0]][j] = i + 1
        for j in range(ilst[i + 1][1], W):
            c[ilst[i + 1][0]][j] = i + 2
    else:
        if c[ilst[i][0]][0] == '.':
            for j in range(W):
                c[ilst[i][0]][j] = i + 1
    if c[ilst[i][0]] != '.':
        if nlst == []:
            nlst.append(ilst[i][0])
        elif nlst[-1] != ilst[i][0]:
            nlst.append(ilst[i][0])
copyi = 0
for i in range(H):
    if c[i][0] == '.':
        copyi = bisect.bisect_left(nlst, i)
        if copyi <= len(nlst) - 1:
            c[i] = copy.copy(c[nlst[copyi]])
        else:
            c[i] = copy.copy(c[nlst[copyi - 1]])

for i in range(H):
    for j in range(W):
        if j != W - 1:
            print(c[i][j], end=' ')
        else:
            print(c[i][j])

Buggy submission (verdict: Runtime Error):
import queue

H, W, K = map(int, input().split())
c = [list(input()) for _ in range(H)]
moveRow = [0, 1, -1, 0]
moveCol = [1, 0, 0, -1]
ilst = []
index = 1
for i in range(H):
    for j in range(W):
        if c[i][j] == '#':
            c[i][j] = index
            index += 1
            ilst.append([i, j])

for i in range(K - 1):
    if ilst[i][0] == ilst[i + 1][0]:
        cindex = 0
        if c[ilst[i][0]][0] != '.':
            cindex = ilst[i][1]
        for j in range(cindex, ilst[i + 1][1]):
            c[ilst[i][0]][j] = i + 1
        for j in range(ilst[i + 1][1], W):
            c[ilst[i + 1][0]][j] = i + 2
    else:
        if c[ilst[i][0]][0] == '.':
            for j in range(W):
                c[ilst[i][0]][j] = i + 1
for i in range(H - 1):
    for j in range(W):
        if c[i][j] == '.':
            c[i][j] = c[i + 1][j]

for i in range(W):
    if c[-1][i] == '.':
        c[-1][i] = c[-2][i]


for i in range(H):
    for j in range(W):
        if j != W - 1:
            print(c[i][j], end = ' ')
        else:
            print(c[i][j])