Problem p02614 (python)

Fixed submission:

import numpy as np

H, W, K = map(int,input().split())
D = np.zeros([H,W])

black_count = 0
for i in range(H):
    C = list(input())
    for j in range(len(C)):
        if(C[j] == "#"):
            D[i][j] = 1


#print(D)
for i in range(2**H):
    h = format(i, '06b')
    for j in range(2**W):
        w = format(j, '06b')
        d = D.copy()

        for hi in range(H):
            if(h[5-hi] == '1'):
                d[hi,:]=0
        for wi in range(W):
            if(w[5-wi] == '1'):
                d[:,wi]=0
            
        if (d.sum() == K):
            black_count += 1

print(black_count)

Buggy submission (verdict: Runtime Error):

import numpy as np
import os

def bcount(C):
    u, counts = np.unique(C, return_counts=True)
    return counts[0]


def main():
    H, W, K = map(int,input().split())
    C = []
    form1 = '0'+str(W)+'b'
    form2 = '0'+str(H)+'b'
    h2 = [str(format(i, form2)).split('b')[0] for i in range(2**H)]
    w2 = [str(format(i, form1)).split('b')[0] for i in range(2**W)]
    default_count = 0
    black_count = 0
    for i in range(H):
        C.append(list(map(str, list(input()))))
        default_count += C[i].count("#")
    print(default_count)
    
    if default_count == K:
        print(1)
        os._exit(1)
    elif default_count < K:
        print(0)
        os._exit(1)
    C = np.array(C,dtype = str)

    for i in range(len(h2)):
        co = np.copy(C)
        tmp = list(h2[i])
        for j in range(len(tmp)):
            if(tmp[j] == '1'):
                co[j,:] = "%"
        for k in range(len(w2)):
            co2 = np.copy(co)
            tmp = list(w2[k])
            for j in range(len(tmp)):
                if(tmp[j] == '1'):
                    co2[:,j] = "%"
            if (bcount(co2) == K):
                black_count += 1

    print(black_count)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):

import numpy as np
import os

def bcount(C):
    u, counts = np.unique(C, return_counts=True)
    return counts[0]


def main():
    H, W, K = map(int,input().split())
    C = []
    form1 = '0'+str(W)+'b'
    form2 = '0'+str(H)+'b'
    h2 = [str(format(i, form2)).split('b')[0] for i in range(2**H)]
    w2 = [str(format(i, form1)).split('b')[0] for i in range(2**W)]
    default_count = 0
    black_count = 0
    for i in range(H):
        C.append(list(map(str, list(input()))))
        default_count += C[i].count("#")
    print(default_count)
    
    if default_count == K:
        print(1)
        os._exit(1)
    elif default_count < K:
        print(0)
        os._exit(1)
    C = np.array(C,dtype = str)

    for i in range(len(h2)):
        co = np.copy(C)
        tmp = list(h2[i])
        for j in range(len(tmp)):
            if(tmp[j] == '1'):
                co[j,:] = "%"
        if (bcount(co) == K):
            black_count += 1

        for k in range(len(w2)):
            co2 = np.copy(co)
            tmp = list(w2[k])
            for j in range(len(tmp)):
                if(tmp[j] == '1'):
                    co2[:,j] = "%"
            if (bcount(co2) == K):
                black_count += 1

    print(black_count)

if __name__ == "__main__":
    main()