Problem:


Score : 300 points

Problem Statement

We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is ., and black if c_{i,j} is #.

Consider doing the following operation:

Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns.

You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.

Constraints

1 \leq H, W \leq 6

1 \leq K \leq HW

c_{i,j} is . or #.

Input

Input is given from Standard Input in the following format:

H W K
c_{1,1}c_{1,2}...c_{1,W}
c_{2,1}c_{2,2}...c_{2,W}
:
c_{H,1}c_{H,2}...c_{H,W}

Output

Print an integer representing the number of choices of rows and columns satisfying the condition.

Sample Input 1

2 3 2
..#
###

Sample Output 1

5

Five choices below satisfy the condition.

The 1-st row and 1-st column

The 1-st row and 2-nd column

The 1-st row and 3-rd column

The 1-st and 2-nd column

The 3-rd column

Sample Input 2

2 3 4
..#
###

Sample Output 2

1

One choice, which is choosing nothing, satisfies the condition.

Sample Input 3

2 2 3
##
##

Sample Output 3

0

Sample Input 4

6 6 8
..##..
.#..#.
#....#
######
#....#
#....#

Sample Output 4

208



Sample input:
2 3 2
..#
###


Sample output:
5

Submission status: Wrong Answer

Solution code:
import numpy as np

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

c = [[1 if s=="#" else 0 for s in input()] for _ in range(H)]

def func(mats, ans, h, hmax, w, wmax):
  buf = []
  if h<hmax:
    for mat in mats:
      m = mat.copy()
      m[h,:] = 0
      s = m.sum()
      if s>K:
        buf.append(m)
      if s==K:
        ans.append(m)
      buf.append(mat)
    func(buf, ans, h+1, hmax, w, wmax)
  elif w < wmax:
    for mat in mats:
      m = mat.copy()
      m[:,w] = 0
      s = m.sum()
      if s>K:
        buf.append(m)
      if s==K:
        ans.append(m)
      buf.append(mat)
    func(buf, ans, h, hmax, w+1, wmax)
  else:
    return

ans = []
func([np.array(c)], ans, 0, H, 0, W)
print(len(ans))

Submission status: Wrong Answer

Solution code:
import itertools

h,w,k=[int(x) for x in input().rstrip().split()]
l=[]
bl=0
yoko=[]
tate=[]
ans=0
for i in range(h):
  W=[x for x in input()]
  l.append(W)
  bl=0
  for s in W:
    if s=="#":
      bl+=1
  yoko.append(bl)

for i in range(w):
  bl=0
  for j in range(h):
    if l[j][i]=="#":
      bl+=1
  tate.append(bl)

if sum(tate)==k:
  ans=1
else:
  ans=0

Y=[]
y_l=[i for i in range(len(yoko))]
for i in range(1,len(yoko)+1):
  
  for ii in itertools.combinations(y_l,i):
    a=sum(ii)
    if a==k:ans+=1
    Y.append(ii)

t_l=[i for i in range(len(tate))]
X=[]
for i in range(1,len(tate)+1):
  for ii in itertools.combinations(t_l,i):
    a=sum(ii)
    if a==k:
      ans+=1
    X.append(ii)

# print(X)
# print(Y)
now=0
# for i in range(yoko,)
for i in X:#tate
  for j in Y:#yoko
    
    for ii in i:
      now+=tate[ii]
    for jj in j:
      now+=yoko[jj]

    for jj in j:
      for ii in i:
        if l[jj][ii]=="#":
          now-=1
    
    if sum(tate)-now==k:
      ans+=1
 
    now=0
    
print(ans)

Submission status: Wrong Answer

Solution code:

import sys
import numpy as np

H,W,K=map(int,input().split())
kuro=0
C=[]
yoko=[]
tate=[0]*W
for i in range(H):
    c=list(input())
    cnt=c.count("#")
    yoko.append(cnt)
    kuro+=cnt
    for j in range(W):
        if c[j]=="#":
            tate[j]+=1    
    C.append(c)

Cnum=np.array(C)

nuru=kuro-K

if nuru==0:
    print(1)
    sys.exit()
if nuru<0:
    print(0)
    sys.exit()

ans=0

for i in range(2**H):
    gyou=[0]*H
    for k in range(H):
        if ((i >> k) & 1):
            gyou[H-1-k] = 1
        
        for j in range(2**W):
            retsu=[0]*W
            for l in range(W):
                if ((j >> l) & 1):
                    retsu[W-1-l] =1                    
                
                for m in range(H):
                    if gyou[m]==1:
                        nuru = nuru-yoko[m]
                for n in range(W):
                    if retsu[n]==1:
                        nuru = nuru-tate[n]
                        for o in range(H):
                            if gyou[o]==1 and C[o][n]=="#":
                                nuru+=1
                    if nuru==0:
                        ans+=1
                    nuru=kuro-K
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import itertools
input = lambda: sys.stdin.readline().rstrip()

def main():
    h, w, k = map(int, input().split())
    ans = 0
    grid = []
    index = [i for i in range(h + w)]
    for _ in range(h):
        grid.append(list(input()))
    grid = np.array(grid)
    for i in range(1, h+w+1):
        for combs in itertools.combinations(index, i):
            tmp = grid.copy()
            row, col = [], []
            for comb in combs:
                if comb >= w:
                    row.append(comb - w)
                else:
                    col.append(comb)
            tmp = np.delete(tmp, row, 0)
            tmp = np.delete(tmp, col, 1)
            if np.count_nonzero(tmp == '#') == k:
                ans += 1
    print(ans)                
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np 
h,w,k=map(int,input().split())
c=[None]*h
for i in range(h):
  c[i]=list(map(int,input().replace(".","0 ").replace("#","1 ").split()))
#sum_c=sum(c)
d=np.array(c)
c=np.copy(d)
e=np.copy(d)
r=0
#h+=-1
#w+=-1
for j in range(2**h):
  j_b=bin(j)[:1:-1]
  e=np.copy(c)
  #print(j)
  for i_j,d_j in enumerate(j_b):
    #print(d_j)
    if d_j=="1":
      #print(d[i_j])
      e[i_j]=0
      #print(d)
    #else:
    #  e[i_j]=c[i_j]
    for m in range(2**w):
      d=np.copy(e)
      #print(m)
      m_b=bin(m)[:1:-1]
      #print(j_b)
      #print(m_b)
      for i_m,d_m in enumerate(m_b):
        if d_m=="1":
          d[:,i_m]=0
        #else:
          #print(m_b)
        #  d[:,i_m]=c[:,i_m]
      #print(d)
      if np.sum(d)==k:
        r+=1
        #print(m_b)
        #rint(j_b)
        #print(d)
      #d=np.copy(e)
    #d=np.copy(c)
print(r)

Submission status: Wrong Answer

Solution code:
H, W, K = map(int, input().split())
M = [str(input()) for i in range(H)]
#print(M)

site = []
for h in range(H):
  s = []
  for w in range(W):
    s.append(M[h][w])
  site.append(s)
#print(site)

if sum(x.count('#') for x in site) == K:
  print(1)
else:
  ans = 0

Submission status: Wrong Answer

Solution code:
import itertools

h, w, k = map(int, input().split())
s = [0] * h
countH = [0] * h
countW = [0] * w
ans = []
ans_sub = [[0 for j in range(2)] for i in range(h * w)]
num = 0
ans_count = 0

for i in range(h):
    s[i] = list(input())
    for j in range(w):
        if s[i][j] == '#':
            ans_sub[num][0] = i
            ans_sub[num][1] = j + 2
            ans.append(ans_sub[num])
            num += 1

lis = list(range(h + w))

for n in range(h + w):
    for pair in itertools.combinations(lis, n + 1):
        count = 0
        for i in range(len(ans)):  # blacklist
            if (ans[i][0] not in pair) and (ans[i][1] not in pair):
                count += 1  # その黒がけずられないか
                #print(count)
            
        if count == k:
            #print(len(ans), count)
            ans_count += 1
            #print(ans_count)
if k == len(ans):
    ans_count += 1

print(ans_count)

Submission status: Wrong Answer

Solution code:
import itertools
import copy

h, w, k = map(int, input().split())
c = []
ans = 0

for i in range(h):
    c.append(input())

hr = 0
ht = list(range(1, h + 1))
wt = list(range(w))

while True:
    if hr == 0:
        for wr in range(w):
            t = copy.copy(c)
            for wm in itertools.combinations(wt, wr):
                u = copy.copy(t)
                for wmm in wm:
                    i = 0
                    for e in u:
                        e = e[:(wmm)] + '.' + e[(wmm + 1):]
                        u[i] = e
                        i += 1
                if ''.join(u).count('#') == k:
                    ans += 1
    else:
        for hm in itertools.combinations(ht, hr):
            t = copy.copy(c)
            for hmm in hm:
                t[hmm - 1] = '.' * w

            if ''.join(t).count('#') > k:
                for wr in range(w):
                    for wm in itertools.combinations(wt, wr):
                        u = copy.copy(t)
                        for wmm in wm:
                            i = 0
                            for e in u:
                                e = e[:(wmm)] + '.' + e[(wmm + 1):]
                                u[i] = e
                                i += 1

                        if ''.join(u).count('#') == k:
                            ans += 1

            elif ''.join(t).count('#') == k:
                ans += 1

    hr += 1
    if hr > h:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
h,w,k = map(int,input().split())
c = [[0]*w]*h
for i in range(h):
	c[i] = input()
	c[i] = list(c[i])

counter = 0	
ans = 0
b = 0
for (i,j) in itertools.product(range(h), range(w)):
	if c[i][j] == '#':
		b += 1
if b == k:
	ans += 1

for hl in range(1,h+1):
	for wl in range(1,w+1):
		for	hi in itertools.combinations(range(h),hl):
			for wj in itertools.combinations(range(w),wl):
				for i in hi:
					for j in range(w):
						if c[i][j] == '#':
							counter += 1
				for j in wj:
					for i in range(h):
						if c[i][j] == '#':
							counter += 1
				if b - counter == k:
					ans += 1
				counter = 0
for hl in range(h+1):
	for hi in itertools.combinations(range(h),hl):
		for i in hi:
			for j in range(w):
				if c[i][j] == '#':
					counter += 1
		if b - counter == k:
				ans += 1
				counter = 0
for wl in range(w+1):
	for wj in itertools.combinations(range(w),wl):
		for j in wj:
			for i in range(h):
				if c[i][j] == '#':
					counter += 1
		if b - counter == k:
				ans += 1
				counter = 0
print(ans)

Submission status: Wrong Answer

Solution code:
h,w,k = map(int,input().split())
c = [list(input()) for i in range(h)]
wi = [0 for i in range(w)]
hi = [0 for i in range(h)]
bl = 0
for i in range(h):
  for j in range(w):
    if c[i][j]=="#":
      wi[j] += 1
      hi[i] += 1
      bl += 1
ans = 0
from itertools import product
cou = 0
for i in product((0, 1), repeat=h):
    cou = 0
   # print("i",i)
    for p in range(h):
      x = i[p]
      y = hi[p]
      if x==1:
        cou += y
   #   print("h",x,y,cou)
    for j in product((0, 1), repeat=w):
     #     print("w",j)
        for v in range(w):
          r = j[v]
          t = wi[v]
          if r==1:
              cou += t
    #      print("w",r,t,cou)
        for e in range(h):
          for l in range(w):
            if i[e]==1 and j[l]==1 and c[e][l]=="#":
              cou -= 1

        if bl-cou == k:
          ans += 1
        cou = 0
       #   print("ans",ans,cou)  

      
print(ans)

Submission status: Wrong Answer

Solution code:
H,W,K=map(int,input().split())
C=[[] for i in range(H)]
for i in range(H):
    C[i]=input()
D=[[0 for j in range(W)] for i in range(H)]
for i in range(H):
    for j in range(W):
        if C[i][j]=="#":
            D[i][j]=1
r = [i for i in range(H)]
c = [i for i in range(W)]
count=0
for i in range(2 ** H):
    for j in range(2 ** W):
        E=D
        a = []
        b = []
        for k in range(H):
            if ((i >> k) & 1):
                a.append(r[k])
        for l in range(W):
            if ((j >> l) & 1):
                b.append(c[l])
        for m in a:
            for n in b:
                E[m][n]=0
        sum_=0
        for i in range(H):
            sum_=sum(E[i])
        if sum_==K:
            count+=1
print(count)

Submission status: Wrong Answer

Solution code:
h,w,k = map(int,input().split())
c = [list(input()) for i in range(h)]
cnt = 0
for i in range(h):
  for j in range(i,h):
    c[j] = ["r"]*w
    for k in range(w):
      for l in range(k,w):
        c[i][l] = "r"
      aaa = 0
      for a in range(h):
        aaa += c[a].count("#")
      if aaa == k:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
row, col, K = map(int, input().split())

cells = []
for i in range(row):
    # 1行分の文字列を追加
    cells.append(input())

# 初期状態の黒マスの数
num_of_blackcell = ''.join(cells).count('#')

# 初期状態の黒マスがKより小さい場合
if num_of_blackcell < K:
    print(0)
    exit()

# 初期状態の黒マスとKが同値の場合
if num_of_blackcell == K:
    # 何も選ばない1通り
    print(1)
    exit()


from itertools import combinations

def SumTheList(thelist, target):
    arr = []
    num_of_combinations = 0

    # リストからr個を抽出する組み合わせのリストを生成し、保存する
    # rは1からリストの長さまで順次確認する
    for r in range(1, len(thelist) + 1):
        arr += list(combinations(thelist, r))

    for item in arr:
        if sum(item) == target:
            # 合計がtargetと合致する組み合わせがあれば組み合わせ数に加算する
            num_of_combinations += 1

    return num_of_combinations

ans = 0

#########################
# 行だけのパターンを確認
#########################
# 消したい黒マスの数
num_of_delete_blackcell = num_of_blackcell - K

# 行ごとに存在する黒マスの数のリスト
num_of_row_blackcells = []
for i in range(row):
    num_of_row_blackcells.append(cells[i].count('#'))

# 消したい黒マスの数を満たす組み合わせ数を算出
ans += SumTheList(num_of_row_blackcells, num_of_delete_blackcell)

#########################
# 列だけのパターンを確認
#########################
# 列ごとに存在する黒マスの数のリスト
num_of_col_blackcells = [0] * col
for i in range(row):
    for j in range(col):
        if cells[i][j] == '#':
            num_of_col_blackcells[j] += 1

# 消したい黒マスの数を満たす組み合わせ数を算出
ans += SumTheList(num_of_col_blackcells, num_of_delete_blackcell)

# 全行・全列埋めが発生していたら1を引く(=Kが0)
if K == 0:
    ans -= 1

# 行・列混在のパターンを確認
from itertools import product

for p in product((0, 1), repeat=row):
    # 行数の中から任意の行に1を立てた組み合わせを全探索

    # 使用する行のインデックスリスト
    tmp_rows = [i for i, x in enumerate(p) if x == 1]

    # 全行抽出しない　または　全行抽出　は除外する
    if len(tmp_rows) != 0 and len(tmp_rows) != row:
        tmp_cells = cells.copy()
        # インデックスがずれないように逆順で削除
        for i in sorted(tmp_rows, reverse=True):
            tmp_cells.pop(i)

        # 列ごとに存在する黒マスの数のリスト
        num_of_col_blackcells = [0] * col
        for i in range(len(tmp_cells)):
            for j in range(col):
                if cells[i][j] == '#':
                    num_of_col_blackcells[j] += 1
        
        # 消したい黒マスから行選択で消された黒マスは除外する
        num_of_deletedblackcells = 0
        for tmp_cell in tmp_cells:
            num_of_deletedblackcells += ''.join(tmp_cell).count('#')

        # 消したい黒マスの数を満たす組み合わせ数を算出
        ans += SumTheList(num_of_col_blackcells, num_of_delete_blackcell - num_of_deletedblackcells)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys, copy
input = sys.stdin.readline
def main():
    h, w , k = map(int, input().split())
    ls = []
    for _ in range(h):
        ms = []
        t=str(input().rstrip())
        for i in range(len(t)):
            if t[i] =='.':
                ms.append(0)
            else:
                ms.append(1)
        ls.append(ms)

    def num(x, y):
        lt = copy.deepcopy(ls)
        x2 = format(x, 'b')
        y2 = format(y, 'b')
        for i in range(len(x2)):
            if x2[i]=='0':
                lt[i]= [0]*len(y2)
        for j in range(len(y2)):
            if y2[j]=='0':
                for t in range(len(x2)):
                    lt[t][j]= 0
        re = 0
        for i in lt:
            re += sum(i)
        return re

    ans = 0
    for i in range(2**h):
        for j in range(2**w):
            if num(i,j) == k:
                ans +=1
                print(i, j)
    print(ans)
    print(ls)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
h,w,k=map(int,input().split())
c=list()
for i in range(h):
  d=list(input())
  c.append(d)


num_h = 2**(h+1)
num_w = 2**(w+1)
result = 0
for i in range(num_h):
  for j in range(num_w):
    tmp = 0
    for row in range(h):
      for col in range(w):
        if (j >> row) & 1 == 0:
          if (i >> col) & 1 == 0:
            if c[row][col] == '#':
              tmp += 1
    if tmp == k:
      result += 1
if result >= 4:
  result /= 4
print(int(result))

Submission status: Wrong Answer

Solution code:
import itertools
import copy
H,W,K= map(int,input().split())
List=[list(input()) for i in range(H)]
nums=[]
total=0
for i in range(1,H+W+1):
    nums.append(i)
for q in range(0,H+W+1):
    hoge=[]
    for balls in itertools.combinations(nums, q):
        hoge.append(balls)
    for p in range(0,len(hoge)):
        Listo=copy.copy(List)
        for i in range(1,H+1):
            if i in hoge[p]:
                for j in range(0,W):
                    Listo[i-1][j]="x"
        for i in range(H+1,H+W+1):
            if i in hoge[p]:
                for j in range(0,H):
                    Listo[j][i-H-1]="x"
        s=0
        for i in range(0,H):
            for j in range(0,W):
                if Listo[i][j]=="#":
                    s+=1
        if s== K:
            total+=1
print(total)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

board = np.zeros((H, W), dtype=np.uint8)

for h in range(H):
    S = input()
    print(S)
    for w in range(W):
        if S[w] == '#':
            board[h][w] = 1

hlist = board.sum(axis=1)
wlist = board.sum(axis=0)

hbitlist = np.asarray( [ (2**h)*(2**W) for h in range(H) ] )
wbitlist = np.asarray( [  2**w  for w in range(W) ] )

ret = 0
i = 0
loopnum = (2**H)*(2**W)
while True:
    htarget = i & hbitlist
    wtarget = i & wbitlist
    sumnum = 0
    for h in range(H):
            for w in range(W):
                if (htarget[h]==0) and (wtarget[w]==0):
                    print(board[h][w])
                    sumnum += board[h][w]
    if sumnum == K:
        ret += 1
    i+=1
    if i>=loopnum:
        break

print(ret)

Submission status: Wrong Answer

Solution code:
h,w,k = list(map(int,input().split(" ")))
colors=[]
for i in range(h):
  colors.append(list(input()))
s=0
d=0
print(colors)
for x in colors:
  s += x.count("#")
  d += x.count(".")
if s == k:
  print(1)
elif s < k:
  print(0)
else:
  count=0
  for j in range(h):
    x= colors[j].count("#")
    if (s-x) ==k:
      count +=1
 
    for l in range(w):
      b = 0
      for m in range(h):
        if colors[m][l]=="#":
          b += 1
      if colors[j][l]=="#":
        b -= 1
      if (s - x -b)==k:
        count +=1
    print(count)
    
    for l in range(w):
      c = 0
      for m in range(h):
        if colors[m][l]=="#":
          c += 1
      if colors[j][l]=="#":
         c -= 1
    if (s - c)==k:
      count += 1
  print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
gen_input = list(map(int, input().split()))
H = gen_input[0]
W = gen_input[1]
K = gen_input[2]
string = [list(input()) for n in range(H)]

for i in range(len(string)):
    for j in range(len(string[0])):
        if string[i][j] == '.':
            string[i][j] = 100
        else:
            string[i][j] = 1000
            
string = np.array(string)

count = 0
for i in range(2**H):
    for j in range(2**W):
        temp = string.copy()
        I = list(bin(i)[2:].zfill(H))
        J = list(bin(j)[2:].zfill(W))
        fill_h = np.where(np.array(list(map(int, list(I)))) == 1)[0]
        fill_w = np.where(np.array(list(map(int, list(J)))) == 1)[0]
        if (string == 1000).sum() == K:
            count += 1
        if len(fill_h) > 0 and len(fill_w) == 0:
            for f in fill_h:
                temp[f, :] = 0
            if (temp == 1000).sum() == K:
                count += 1
        elif len(fill_h) == 0 and len(fill_w) > 0:
            for f in fill_w:
                temp[:, f] = 0
            if (temp == 1000).sum() == K:
                count += 1
        elif len(fill_h) > 0 and len(fill_w) > 0:
            for f in fill_h:
                temp[f, :] = 0
            for f in fill_w:
                temp[:, f] = 0
            if (temp == 1000).sum() == K:
                count += 1

print(count)

Submission status: Wrong Answer

Solution code:
H, W, K = map(int, input().split())
C = [list(input()) for i in range(H)]


C = [[s.replace(".", "0") for s in t] for t in C]
C = [[s.replace("#", "1") for s in t] for t in C]
C = [[int(s) for s in t] for t in C]

total = sum([sum(i) for i in C])
C_T = list(map(list, zip(*C)))

count = 0
if total == K:
    count += 1
else:
    for i in range(H):
        if total - sum(C[i]) == K:
            count += 1
    for j in range(W):
        if total - sum(C_T[j]) == K:
            count += 1
    for i in range(H):
        for j in range(W):
            if total - (sum(C[i]) + sum(C_T[j]) - C[i][j]) == K:
                    count += 1
                    print(C[i], C_T[j])
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

def HandV():

    num = list(map(int,input().split()))

    list_result = []

    nun_black = 0
    nun_white = 0

    for n1 in range(num[0]):
        gyou = str(input())
    
        list_gyou = []
        for n2 in range(num[1]):
            list_gyou.append(gyou[n2])
    
        list_result.append(list_gyou)
    
        nun_black = nun_black + list_gyou.count('#')
        nun_white = nun_white + list_gyou.count('.')

    array = np.array(list_result)

    count_num = 0

    for i in range(num[0] + 1):

        array_test = array
 

        if i!=0:
            
            if nun_black - np.count_nonzero(array_test[i-1,:] == '#') == num[2]:
                count_num = count_num + 1

            for i2 in range(i+1, num[0] + 1):
        
                if nun_black - np.count_nonzero(array_test[i-1,:] == '#')- np.count_nonzero(array_test[i2-1,:] == '#') == num[2]:
                    count_num = count_num + 1

    
        for j in range(num[1]+1):
        
            if i==0 and j==0:
                if np.count_nonzero(array == '#') == num[2]:
                    count_num = count_num + 1


            elif i==0 and j!=0:
                if nun_black - np.count_nonzero(array_test[:,j-1] == '#') == num[2]:
                    count_num = count_num + 1

            
                for j2 in range(j+1, num[1] + 1):
            
                    if nun_black - np.count_nonzero(array_test[:,j-1] == '#') - np.count_nonzero(array_test[:,j2-1] == '#') == num[2]:
                        count_num = count_num + 1
        
            
            elif i!=0 and j!=0:
                if nun_black - np.count_nonzero(array_test[i-1,:] == '#') - np.count_nonzero(array_test[:,j-1] == '#') + np.count_nonzero(array_test[i-1,j-1] == '#') == num[2]:
                    count_num = count_num + 1
    

    
    print(count_num)

if __name__ == '__main__':
    HandV()

Submission status: Wrong Answer

Solution code:
import itertools

h,w,k = map(int, input().split())

c = [list(input()) for l in range(h)]

#print(c)
brack_con=0
brack_w=[0]*w
brack=[0]*h

for i in range(h):
    brack_con=brack_con+c[i].count('#')
    brack[i]=c[i].count('#')
for e in range(h):
    for o in range(w):
        brack_w[o]+=c[e][o].count('#')
ans=0
dele=brack_con-k
b_pairs = []
bw_pairs = []
if dele<0:
    ans=0
    print(ans)
else:
    if k==brack_con:
        ans+=1

    for i in range(1, h+1):
        b_pairs += itertools.combinations(brack, i)
    for i in range(len(b_pairs)):
        if sum(b_pairs[i])==dele:
            ans+=1

    for i in range(1, w+1):
        bw_pairs += itertools.combinations(brack_w, i)
    for i in range(len(bw_pairs)):
        if sum(bw_pairs[i])==dele:
            ans+=1

    for i in range(len(b_pairs)):
        for e in range(len(bw_pairs)):
            if (sum(b_pairs[i])+sum(bw_pairs[e])==dele):
                #print(i,e)

                ans+=1

    #print(b_pairs)
   # print(b_pairs)
    print(ans)

Submission status: Wrong Answer

Solution code:
h,w,k = map(int,input().split())
board = []
for i in range(h):
    row = input()
    board.append(row)
def countblack(board):
    num = 0
    for i in board:
        for j in len(i):
            if i[j] == '#':
                num+= 1
    return num
print(0)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jul  5 21:10:49 2020

@author: Aruto Hosaka
"""


H,W,K = map(int,input().split())
C = [input() for i in range(H)]

# H,W,K = 6,6,8
# C = ['..##..', '.#..#.', '#....#', '######', '#....#', '#....#']

# H,W,K = 6,6,8
# C = [['..##..'], ['.#..#.'], ['#....#'], ['######'], ['#....#'], ['#....#']]

Cn = [[0 for w in range(W)] for h in range (H)]

for h in range(H):
    for w in range(W):
        if C[h][w] == '.':
            Cn[h][w] = 0
        else:
            Cn[h][w] = 1

counter1 = 0

ii = 0

for i in range(2**H):
# for i in range(2):
    for j in range(2**W):
    # for j in range(2):
        i = ii
        for h in reversed(range(H)):
            if i >= 2**h:
                for w2 in range(W):
                    Cn[h][w2] = 0
                i += -2**h
        for w in reversed(range(W)):
            if j >= 2**w:
                for h2 in range(H):
                    Cn[h2][w] = 0
                j += -2**w
        counter = 0
        for h in range(H):    
            counter += sum(Cn[h])
        
        print(Cn)
        print(counter)
        if counter == K:
            counter1 += 1
        
        for h in range(H):
            for w in range(W):
                if C[h][w] == '.':
                    Cn[h][w] = 0
                else:
                    Cn[h][w] = 1
    ii += 1
print(counter1)

Submission status: Wrong Answer

Solution code:
h,w,k=map(int,input().split())
c=list()
for i in range(h):
  d=list(input())
  c.append(d)


num_h = 2**(h+1)
num_w = 2**(w+1)
result = 0
for i in range(num_h):
  for j in range(num_w):
    tmp = 0
    for row in range(h):
      for col in range(w):
        if (j >> row) & 1 == 0:
          if (i >> col) & 1 == 0:
            if c[row][col] == '#':
              tmp += 1
    if tmp == k:
      result += 1
print(int(result/4))

Submission status: Wrong Answer

Solution code:
import numpy as np

H,W,K=map(int,input().split())
A=[]
for i in range(H):
    B=list(input())
    for i in B:
        if i==".":
            A.append(0)
        else:
            A.append(1)
A=np.array(A)
A=A.reshape(H,W)
K=np.sum(A)-K
#選んだ行と列に含まれるものを0にする
#K個消せればよい
#bit全探索ならできるか
cnt=0
for i in range(2**H):
  a=0
  C=[]
  for j in range(H):
    if (i>>j)&1:
      C.append(j)
      a+=np.sum(A[j])
      
    for k in range(2**W):
      for l in range(W):
        if (k>>l)&1:
          a+=np.sum(A[:,l])
        for m in C:
          a-=A[m,l]
      if a==K:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
h,w,k=map(int,input().split())
c=list()
for i in range(h):
  d=list(input())
  c.append(d)


num_h = 2**(h+1)
num_w = 2**(w+1)
result = 0
for i in range(num_h):
  for j in range(num_w):
    tmp = 0
    for row in range(h):
      for col in range(w):
        if (j >> row) & 1 == 0:
          if (i >> col) & 1 == 0:
            if c[row][col] == '#':
              tmp += 1
    if tmp == k:
      result += 1
print(result/4)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jul  5 21:10:49 2020

@author: Aruto Hosaka
"""


H,W,K = map(int,input().split())
C = [input() for i in range(H)]

# H,W,K = 6,6,8
# C = ['..##..', '.#..#.', '#....#', '######', '#....#', '#....#']

# H,W,K = 6,6,8
# C = [['..##..'], ['.#..#.'], ['#....#'], ['######'], ['#....#'], ['#....#']]

Cn = [[0 for w in range(W)] for h in range (H)]

for h in range(H):
    for w in range(W):
        if C[h][w] == '.':
            Cn[h][w] = 0
        else:
            Cn[h][w] = 1

counter1 = 0

ii = 0

for i in range(2**H):
# for i in range(2):
    for j in range(2**W):
    # for j in range(2):
        i = ii
        for h in reversed(range(H)):
            if i >= 2**h:
                for w2 in range(W):
                    Cn[h][w2] = 0
                i += -2**h
        for w in reversed(range(W)):
            if j >= 2**w:
                for h2 in range(H):
                    Cn[h2][w] = 0
                j += -2**w
        counter = 0
        for h in range(H):    
            counter += sum(Cn[h])
        
        print(Cn)
        print(counter)
        if counter == K:
            counter1 += 1
        
        for h in range(H):
            for w in range(W):
                if C[h][w] == '.':
                    Cn[h][w] = 0
                else:
                    Cn[h][w] = 1
    ii += 1

Submission status: Wrong Answer

Solution code:
import itertools
import copy

h, w, k = map(int, input().split())
c = []
for i in range(h):
  s = input()
  c.append(list(s))
f = ['0', '1']
c2 = []
ans = 0
for i in itertools.product(f, repeat=h):
  c2.clear()
  c2 += c
  for x in range(h):
    if i[x] == '1':
      c2[x] = ['x'] * w
  c3 = []
  for j in itertools.product(f, repeat=w):
    c3.clear()
    c3 = copy.deepcopy(c2)
    for y in range(w):
      if j[y] == '1':
        for k in range(h):
          c3[k][y] = 'x'
    t = 0
    for z in range(h):
      t += c3[z].count('#')
    if t == k:
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
H,W,K = map(int,input().split())
board = [list(input()) for _ in range(H)]
ans = 0

for i in range(2**H-1):
  part1 = []
  part1 += board
  for j in range(H):
    if (i>>j)&1:
      part1[j] = ["*"]*W  
  for k in range(2**W-1):
    part2 = []
    part2 += part1
    for l in range(W):
      if (k>>l)&1:
        for n in range(H):
          part2[n][l] = "*"
    cnt = 0
    for m in part2:
      cnt += m.count("#")
    if cnt == K:
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#ダメでした
print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np
gen_input = list(map(int, input().split()))
H = gen_input[0]
W = gen_input[1]
K = gen_input[2]
string = [list(input()) for n in range(H)]

for i in range(len(string)):
    for j in range(len(string[0])):
        if string[i][j] == '.':
            string[i][j] = 100
        else:
            string[i][j] = 1000
            
string = np.array(string)

if (string == 1000).sum() == K:
    print(1)
else:
    count = 0
    for i in range(2**H):
        for j in range(2**W):
            temp = string.copy()
            I = list(bin(i)[2:].zfill(H))
            J = list(bin(j)[2:].zfill(W))
            fill_h = np.where(np.array(list(map(int, list(I)))) == 1)[0]
            fill_w = np.where(np.array(list(map(int, list(J)))) == 1)[0]
            if len(fill_h) > 0 and len(fill_w) == 0:
                for f in fill_h:
                    temp[f, :] = 0
                if (temp == 1000).sum() == K:
                    count += 1
            elif len(fill_h) == 0 and len(fill_w) > 0:
                for f in fill_w:
                    temp[:, f] = 0
                if (temp == 1000).sum() == K:
                    count += 1
            elif len(fill_h) > 0 and len(fill_w) > 0:
                for f in fill_h:
                    temp[f, :] = 0
                for f in fill_w:
                    temp[:, f] = 0
                if (temp == 1000).sum() == K:
                    count += 1
                
    print(count)

Submission status: Wrong Answer

Solution code:
import copy
import numpy as np
H,W,K = list(map(int, input().split()))
g = [list(input()) for i in range(H)] 
gg = copy.deepcopy(g)

if gg.count("#") < K:
    print(0)
else:
    pass