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 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
C = c
for hl in range(h+1):
	for wl in range(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
							c[i][j] == '.'
				for j in wj:
					for i in range(h):
						if c[i][j] == '#':
							counter += 1
				if b - counter == k:
					ans += 1
				counter = 0
				c = C
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import copy

H, W, K = map(int,input().split())
cl = []
cnt = 0
for i in range(H):
    c = list(input())
    cnt += c.count('#')
    cl.append(c)

if cnt == K:
    print(1)
    exit()

rows = []
for i in range(H+1):
    for v in itertools.combinations(range(H),i):
        rows.append(v)

columns = []
for i in range(W+1):
    for v in itertools.combinations(range(W),i):
        columns.append(v)

ans = 0
tmp_cl = copy.deepcopy(cl)
for i in range(len(rows)):
    for j in range(len(columns)):
        row = rows[i]
        column = columns[j]
        for a in range(len(row)):
            for b in range(W):
                tmp_cl[row[a]][b] = '.'
        for c in range(H):
            for d in range(len(column)):
                tmp_cl[c][column[d]] = '.'

        if list(itertools.chain.from_iterable(tmp_cl)).count('#') == K:
            ans += 1
        tmp_cl = copy.deepcopy(cl)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

def row_red(_R,FR):
    R = _R.copy()
    if not FR:
        return R
    for fr in FR:
        for w in range(len(R[fr])):
            R[fr][w] = 0
    return R

def col_red(_R,FC):
    R = _R.copy()
    if not FC:
        return R
    for fc in FC:
        for h in range(len(R)):
            R[h][fc] = 0
    return R

def comb(item):
    A = []
    n = len(item)
    for i in range(2 ** n):
        bag = []
        for j in range(n):
            if ((i >> j) & 1):
                bag.append(item[j])
        A.append(bag)
    return A

H,W,K = [int(x) for x in input().split()]
r = [[0]*W for i in range(H)]
for i in range(H):
    row = input()
    for j,k in zip(list(row),range(W)):
        if j == "#":
            r[i][k] = 1
        else:
            pass

Row = comb(range(H))
Col = comb(range(W))
count = 0

tmp = [[]*W for i in range(H)]
tmp2 = [[]*W for i in range(H)]

for x in Row:
    tmp = np.array(row_red(r,x))
    t = tmp.copy()
    for y in Col:
        tmp2 = np.array(col_red(t,y))
        if tmp2.sum() == K:
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
h,w,k=map(int,input().split())
c=[]
for i in range(h):
    temp=input()
    c.append(temp)
ans=0
for i in range(2**h):
    for j in range(2**w):
        temp2=[0]*w
        temp=[0]*h
        for m in range(h):
            temp[m]=i&1
            i>>=1
        for m in range(w):
            temp2[m]=j&1
            j>>=1
        cnt=0
        for g in range(h):
            for t in range(w):
                if temp[g]==0 and temp2[t]==0 and c[g][t]=="#": cnt+=1
        if cnt==k: ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
h,w,k=map(int,input().split())
c=[]
for i in range(h):
    temp=input()
    c.append(temp)
ans=0
for i in range(2**h):
    temp=[0]*h
    for m in range(h):
        temp[m]=i&1
        i>>=1
    for j in range(2**w):
        temp2=[0]*w
        for m in range(w):
            temp2[m]=j&1
            j>>=1
        cnt=0
        for g in range(h):
            for t in range(w):
                if temp[g]==0 and temp2[t]==0 and c[g][t]=="#":
                    print(g,t)
                    cnt+=1
        if cnt==k: ans+=1
print(ans)

Submission status: Wrong Answer

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

C = []
for _ in range(H):
    C.append(input())

from pprint import pprint
# pprint(C)
import sys
from collections import Counter
from itertools import product, combinations

counter = Counter()
for row in C:
    counter.update(row)
n_blacks = counter['#']

if n_blacks < K:
    print(0)
    sys.exit()
# elif n_blacks == K:
#     # 黒がいない行、列があると破綻するからこの elif は NG
#     print(1)
#     sys.exit()


board = ''
for row in C:
    board += row

def get_calc_board_index_row(board, n_rows, n_cols):
    b = board
    _n_rows = n_rows
    _n_cols = n_cols
    def fun(n_row):
        # row number
        return list(range(_n_rows * n_row, _n_rows * n_row + _n_cols))
    return fun

calc_board_index_row = get_calc_board_index_row(board=board, n_rows=H, n_cols=W)

def get_calc_board_index_col(board, n_rows, n_cols):
    b = board
    _n_rows = n_rows
    _n_cols = n_cols
    def fun(n_col):
        # row number
        return list(range(
            n_col,
            n_col + _n_rows * _n_cols,
            _n_cols))
    return fun

calc_board_index_col = get_calc_board_index_col(board=board, n_rows=H, n_cols=W)

def get_print_board(board, n_rows, n_cols):
    b = board
    _n_rows = n_rows
    _n_cols = n_cols
    def fun():
        # row number
        for r in _n_rows:
            print(b[r*_n_cols, r*_n_cols+_n_cols])
    return fun

print_board = get_print_board(board, H, W)

# sys.exit()

# 消し込む行と列の数 (n_row, n_col) について、すべてのパターンで繰り返す
# i = 0
ans = 0
for n_row, n_col in product(range(H+1), range(K+1)):
    # n_row 個の行を消し込む場合の、行番号の組み合わせ
    choosed_rows = list(combinations(range(H), n_row))
    # n_col 個の列を消し込む場合の、列番号の組み合わせ
    choosed_cols = list(combinations(range(W), n_col))
    # print(n_row, n_col)
    # 消し込みするマスを計算
    for i_r, i_c in product(range(len(choosed_rows)), range(len(choosed_cols))):
        board_idx = set()
        for _r in choosed_rows[i_r]:
            board_idx.update(calc_board_index_row(_r))
        for _c in choosed_cols[i_c]:
            board_idx.update(calc_board_index_col(_c))

        rest_blacks = 0
        for ix in range(len(board)):
            if ix in board_idx: continue
            if board[ix] == '#':
                rest_blacks += 1
        # pprint({
        #     'choosed_rows': choosed_rows[i_r],
        #     'choosed_cols': choosed_cols[i_c],
        #     'rest_blacks': rest_blacks
        # })

        if rest_blacks == K:
            # print(removing_row_numbers, removing_col_numbers)
            ans += 1
    # print({
    #     'n_row': n_row,
    #     'n_col': n_col,
    #     'choosed_rows': choosed_rows,
    #     'choosed_cols' : choosed_cols,
    #     'board_idx': board_idx,
    #     'rest_blacks': rest_blacks
    # })
    # print()

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import copy

H, W, K = map(int,input().split())
cl = []
cnt = 0
for i in range(H):
    c = list(input())
    cnt += c.count('#')
    cl.append(c)


if cnt == K:
    print(1)
    exit()

rows = []
for i in range(H+1):
    for v in itertools.combinations(range(H),i):
        rows.append(v)

columns = []
for i in range(W+1):
    for v in itertools.combinations(range(W),i):
        columns.append(v)

ans = 0

tmp_cl = copy.deepcopy(cl)
for i in range(len(rows)):
    row = rows[i]
    for j in range(len(columns)):
        column = columns[j]
        for a in range(len(row)):
            for b in range(W):
                tmp_cl[row[a]][b] = '.'
        for c in range(H):
            for d in range(len(column)):
                tmp_cl[c][column[d]] = '.'

        if list(itertools.chain.from_iterable(tmp_cl)).count('#') == K:
            ans += 1
        tmp_cl = copy.deepcopy(cl)
print(ans)

Submission status: Wrong Answer

Solution code:
##a = int(stdin.readline().rstrip())
##b, c = [int(x) for x in stdin.readline().rstrip().split()]
##s = stdin.readline().rstrip()
##a = list(set(b))  重複を削除
##a = list(map(int,[int(x) for x in stdin.readline().rstrip().split()])) a[0, 1, 2, ...]
##a = [[0] * 2 for _ in range(n)]  a[0,0]
##v = [s[i: i+2] for i in range(0, len(s), 2)]
##  s="12345678" を v=["12","34","56","78"] にするイメージ
##s = "".join(list)リストを文字列に変換[""]は区切り文字
##a.sort(key=itemgetter(1))リストをソートできるよ(from operator import itemgetterが必要)
##sort_p = sorted(p) 昇順ソート

# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np
import random
import bisect
import copy
# stdin = open("sample.txt")


MOD = 1000000007
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): # 入力されたintを桁ごとに分解，リストで出力
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): # 最小公倍数
    return reduce(math.gcd, numbers)

def combination(m,n): # mCn
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (x**n)の計算の高速化
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x

def fact(n): # nの素因数分解の結果を辞書で出力 fuct(24) → {2: 3, 3: 1}
    arr = {}
    temp = n
    for i in range(2,int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
    if temp != 1:
        arr[temp] = 1
    if arr == {}:
        arr[n] = 1
    return arr


    
def main():
    h, w, k = [int(x) for x in stdin.readline().rstrip().split()]
    board = []
    kuro = 0
    pattern_h = [[0]*h for _ in range(2 ** h)]
    pattern_w = [[0]*w for _ in range(2 ** w)]
    ans = 0
    nokori = 0
    
    for _ in range(h):
        s = stdin.readline().rstrip()
        v = [s[i] for i in range(0, len(s))]
        kuro += v.count("#")
        board.append(v)
    memo = copy.deepcopy(board)
    
    for i in range(2 ** h):
        for j in range(h):
            if (i >> j) & 1:
                pattern_h[i][j] = j + 1
    for i in range(2 ** w):
        for j in range(w):
            if (i >> j) & 1:
                pattern_w[i][j] = j + 1
                
    for i in range(2 ** w):
        for j in range(w):
            if pattern_w[i][j] != 0:
                for l in range(h):
                    memo[l][j] = "x"
        print(memo)
        for i2 in range(2 ** h):
            for j2 in range(h):
                if pattern_h[i2][j2] == 0:
                    nokori += memo[j2].count("#")
            if k == nokori:
                ans += 1
            nokori = 0
        memo = copy.deepcopy(board)
                        
    print(ans)
                                        
main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

h,w,k = I()
board = []
for i in range(h):
    a = X()
    x = a.count("#")
    count += x
    board.append(a)

gyou = []
retu = []

for i in range(len(board)):
    g = board[i].count("#")
    gyou.append(g)

if k == count:
    print(1)
    sys.exit()

for i in range(w):
    r = 0
    for j in range(h):
        if board[j][i] == "#":
            r += 1
    retu.append(r)

for i in range(h):
    for j in range(w):
        if board[i][j] == "#":
            if count - gyou[i] -retu[j] +1== k:
                ans += 1
        else:
            if count - gyou[i] -retu[j] == k:
                ans += 1

gyou.append(0)
retu.append(0)

for i in list(itertools.combinations(gyou,2)):
    i = list(i)
    ggg = sum(i)
    if count - ggg == k:
        ans += 1

for j in list(itertools.combinations(retu,2)):
    j = list(j)
    rrr = sum(j)
    if count - rrr == k:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

lit = []
for i in range(2 ** H):
    for j in range(2 ** W):
        row = str(bin(i))[2:].zfill(H)
        col = str(bin(j))[2:].zfill(W)
        lit.append([row, col])
# print(len(lit))

black = sum([c.count('#') for c in C])
# print(black)
res = 0
for row, col in lit:
    ans = black
    for i, r in enumerate(row):
        if r == '1':
            ans = black - C[i].count('#')

    for j, c in enumerate(col):
        if c == '1':
            for k in range(H):
                if row[k] == '1':
                    continue
                elif C[k][j] == '#':
                    ans += -1
    if ans == K:
        res += 1

print(res)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np
H, W, K = map(int, input().split())

l = [[0]*W for i in range(H)]
for i in range(H):
  var = input()
  for j in range(W):
    if var[j] == ".":
      l[i][j] += 1
np_l = np.array(l)

#print(l)
h_list = []
for i in range(H):
  var = [j+1 for j in range(H)]
  if i == 0:
    for j in range(H+1):
      h_list.append(j)
  else:
    tmp = list(itertools.combinations(var,i+1))
    for j in range(len(tmp)):
      h_list.append(list(tmp[j]))
w_list = []
for i in range(W):
  var = [j+1 for j in range(W)]
  if i == 0:
    for j in range(W+1):
      w_list.append(j)
  else:
    tmp = list(itertools.combinations(var,i+1))
    for j in range(len(tmp)):
      w_list.append(list(tmp[j]))

ans = 0
for i in range(len(h_list)):
  for j in range(len(w_list)):
    tmp_l = np.copy(np_l)
    try:
      for i2 in range(len(h_list[i])):
        tmp_l[h_list[i][i2]-1] += 2
    except:
      if h_list[i] != 0:
        tmp_l[h_list[i]-1] += 2
    tmp_l = tmp_l.T
    print(tmp_l)
    try:
      for j2 in range(len(w_list[j])):
        tmp_l[w_list[j][j2]-1] += 2
    except:
      if w_list[j] != 0:
        tmp_l[w_list[j]-1] += 2
    tmp_l = tmp_l.T
    b_count = 0
    tmp_l = tmp_l.tolist()
    for i in range(H):
      b_count += tmp_l[i].count(0)
    if b_count == K:
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import copy;

def main():
  H, W, K = list(map(int, input().split()))

  original = [[0 for _ in range(W)] for _ in range(H)]
  ans = 0

  for i in range(H):
    S = [str(s) for s in input()]
    
    for j, v in  enumerate(S):
      if(v == "#"):
        original[i][j] = 1
      else:
        original[i][j] = 0

  print(original)

  for i in range(1 << H):
    for j in range(1 << W):
      m = copy.deepcopy(original);

      count = 0
      for k in range(H):
        if(i >> k & 1):
          m[k] = [0] * W
      
      for k in range(W):
        if(j >> k & 1):
          for l in m:
            l[k] = 0

      for row in m:
        count += row.count(1);

      if(K == count):
        ans += 1

  print(ans)

if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
import collections
H,W,K=map(int,input().split())
info=[]
hinfo=[]
for i in range(H):
  l=input()
  c=collections.Counter(l)
  hinfo.append(c["#"])
  info.append(l)
vinfo=[]
for i in range(W):
  count=0
  for j in range(H):
    if info[j][i]=="#":
      count+=1
  vinfo.append(count)
S=sum(hinfo)
D=S-K
if D==0:
  print(1)
  exit()
else:
  #行のみ
  count=0
  for i in range(H):
    for j in range(i,H):
      s=sum(hinfo[i:j+1])
      if s>D:
        break
      elif s==D:
        count+=1
  #列のみ
  for i in range(W):
    for j in range(i,W):
      s=sum(vinfo[i:j+1])
      if s>D:
        break
      elif s==D:
        count+=1
  #行と列
  for i_1 in range(H):
    for j_1 in range(i_1,H):
      for i_2 in range(W):
        for j_2 in range(i_2,W):
          
          s=sum(hinfo[i_1:j_1+1])+sum(vinfo[i_2:j_2+1])-(j_1-i_1+1)*(j_2-i_2+1)
          
          if s>D:
            break
          elif s==D:
            count+=1        
print(count)

Submission status: Wrong Answer

Solution code:
def main():
    h,w,k=map(int, input().split())
    grid = []
    l = [[0]*w for _ in range(h)]
    ten_g = [0]*(h)
    ten_r = [0]*(w)
    for i in range(h):
        s = list(input().rstrip())
        grid.append(s)
    res = 0
    for bi in range(2**(h+w)):
        tmp = 0
        for i in range(h):
            for j in range(w):
                if(bi & 1<<i and bi&(1<<i+j)):
                    if(grid[i][j]=="#"):
                        tmp+=1
        if(tmp == k):
            res+=1


    print(res)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
h,w,k = list(map(int,input().split()))

c = []
count = 0
for i in range(h):
    cl = list(input())
    c.append(cl)
    count += cl.count("#")

hc = 2 ** h
wc = 2 ** w
result = 0

for i in range(hc):
    for j in range(wc):
        mc = 0
        hc2 = i
        hclis = []
        if i == 0:
            hclis = [0]
        while hc2 != 0:
            hclis.append(hc2 % 2)
            hc2 = hc2 // 2
        wc2 = j
        wclis = []
        if j == 0:
            wclis = [0]
        while wc2 != 0:
            wclis.append(wc2 % 2)
            wc2 = wc2 // 2
        for k1 in range(len(hclis)):
            if i == 4 and j == 4:
                print(mc)
            if hclis[k1] == 1:
                mc += c[k1].count("#")
                if i == 4 and j == 4:
                    print(k1,c[k1].count("#"),mc)
        for k2 in range(len(wclis)):
            if wclis[k2] == 1:
                for l in range(h):
                    if c[l][k2] == "#":
                        mc += 1
        for k1 in range(len(hclis)):
            for k2 in range(len(wclis)):
                if hclis[k1] == 1 and wclis[k2] == 1 and c[k1][k2] == "#":
                    mc -= 1

        if count - mc == k:
            result += 1

print(result)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    H,W,K = map(int, input().split())
    l = []
    for _ in range(H):
        l.append(list(input().rstrip('\n')))
    for i in range(2**H):
        for j in range(2**W):
            b = 0
            for h in range(H):
                for w in range(W):
                    if i>>h & 1 and j>>w & 1 and l[h][w] == '#':
                        b += 1
                if b == K:
                    ans += 1
    print(ans)

if __name__ == '__main__':
    main()

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').rjust(h, '0')
        y2 = format(y, 'b').rjust(w, '0')
        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(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()
sum_=0
for i in range(H):
    for j in range(W):
        if C[i][j]=="#":
            sum_+=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):
        P=sum_
        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:
                if C[m][n]=="#":
                    P-=1
        if P==K:
            count+=1
print(count)

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').rjust(h, '0')
        y2 = format(y, 'b').rjust(w, '0')
        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)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

m = []
n = []
t = []
u = []
ans = 0

for i in range(h):
    s = input()
    n = []
    for j in range(w):
         n.append(s[j])
    m.append(n)

for ii in range(2 ** w):
    tmp = [False] * w
    for jj in range(h):
        if ii >> jj & 1:
            tmp[jj] = True
    t.append(tmp)

for i2 in range(2 ** h):
    tmp = [False] * h
    for j2 in range(w):
        if i2 >> j2 & 1:
            tmp[j2] = True
    u.append(tmp)

for i3 in range(len(t)):
    for i6 in range(len(u)):
        v = m
        for i4 in range(w):
            if t[i3][i4] == True:
                for i5 in range(h):
                    v[i5][i4] = '.'
                
                    for i7 in range(h):
                        if u[i6][i7] == True:
                            for i8 in range(w):
                                v[i7][i8] = '.'
        s2 = 0
        for j3 in range(h):
            s1 = v[j3].count('#')
            s2 = s2 + s1
        if s2 == k:
            ans = ans + 1

print(ans)

Submission status: Wrong Answer

Solution code:
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前
sort()
sorted(reverse=true)
配列の初期化
配列名=[a]*n+[b]*m
Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions
import sys
d = stdin.readline().rstrip().split()
H = int(d[0])
W = int(d[1])
K = int(d[2])

data = []
bCount = 0
result = 0
for el1 in range(H):
    tmp = stdin.readline().rstrip().split()
    d = []
    for el in tmp:
        for el3 in el:
            if el3 == '#':
                bCount += 1
            d.append(el3)
    data.append(d)
datas = copy.deepcopy(data)
counter = 0
for el in range(H+W):
    counter += 2**el
for el in range(counter+1):
    bin_str = ''.join(list(reversed(str(bin(el))[2:])))
    poss = []
    count = 0
    for el2 in bin_str:
        if el2 == '1':
            poss.append(count)
        count += 1
    res = 0
    for el2 in poss:
        if el2 >= H:
            el2 -= H
            for el3 in datas:
                el3[el2] = 'o'
        else:
            datas[el2] = ['o']*W
    for el2 in datas:
        res += el2.count('#')
    if bCount-res == K:
        result += 1
    datas = copy.deepcopy(data)
print(result)

Submission status: Wrong Answer

Solution code:
from itertools import product

h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]

ans = 0
for hl in product([0, 1], repeat=h):
    for wl in product([0, 1], repeat=w):
        cc = c[:]
        for i, hi in enumerate(hl):
            for j, wj in enumerate(wl):
                if hi or wj:
                    cc[i][j] = 'r'
        cnt = 0
        for s in cc:
            cnt += sum(si == '#' for si in s)
        if cnt == k:
            ans += 1
print(ans)

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)]
#print(c)
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 = []
if np.array(c).sum()==K:
  ans.append(np.array(c))
func([np.array(c)], ans, 0, H, 0, W)
print(len(ans))

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)]
print(c)
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 = []
if np.array(c).sum()==K:
  ans.append(np.array(c))
func([np.array(c)], ans, 0, H, 0, W)
print(len(ans))

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:
H, W, K = map(int, input().split())
S = []
for _ in range(H):
    S.append(input())
    


A = [[], [], [], [], [], []]
for i in range(H):
  A[i].append(','.join(map(lambda x: '"{}"'.format(x), S[0])))

#あの、前処理だけはできたんで、これで勘弁してください  
print(A)

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):
                    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=map(int,input().split(" "))

c=[]
for i in range(H):
  a=[str(_) for _ in input()]
  c.append(a)

#count=0
#for o in range(H):
#  for p in range(W):
#    if c[o][p] == "#":
#      count+=1
#print(count)
  
t=c
ans=0
#ccc=0

for i in range(2 ** H):
  c=t
  for j in range(H):  # このループが一番のポイント
    if ((i >> j) & 1):
      for m in range(W):
        c[j][m]="a"
  for k in range(2 ** W):
    #print("ccc",ccc)
    #ccc+=1
    for l in range(H):  # このループが一番のポイント
      if ((k >> l) & 1):
        for n in range(H):
          c[n][l]="a"
    count=0
    for o in range(H):
      for p in range(W):
        if c[o][p] == "#":
          count+=1
    if count == K:
      ans+=1
    
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
h, w, k = map(int, input().split())
c = []
blacks = []
all_b = 0
ans = 0

for i in range(h):
    temp = input()
    temp_list = []
    for t in temp:
        temp_list.append(t)

    c.append(temp_list)
    blacks.append(c[i].count('#'))
    all_b += blacks[i]

c_t = np.array(c).T.tolist()

if all_b == k:
    ans += 1

for i in range(h):
    if k == all_b - blacks[i]:
        ans += 1

for i in range(w):
    if k == all_b - c_t[i].count('#'):
        ans += 1


for i in range(h):
    s = blacks[i]
    for j in range(i+1, h):
        if i != j:
            if k == all_b - s - blacks[j]:
                ans += 1


for i in range(w):
    temp = c_t[i].count('#')
    for j in range(i+1, w):
        if i != j:
            temp_2 = c_t[j].count('#')
            if k == all_b - temp - temp_2:
                ans += 1


for i in range(h):
    s = blacks[i]
    for j in range(w):
        counter_t = c_t[j].count('#')
        if k == all_b - counter_t - s:
            ans += 1


print(ans)

Submission status: Wrong Answer

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

C = []
n = 0
nH = []
nW = [0]*W
for _ in range(H):
    r = 0
    c = input()
    for num, i in enumerate(list(c)):
        if i == '#':
            r += 1
            nW[num] += 1
    n += r
    nH.append(r)
    C.append(c)

nH.append(0)
nW.append(0)

ans = 0
m = n
for i in range(H+1):
    for j in range(W+1):
        m -= (nH[i]+nW[j])
        if not (i == H or j == W):
            if C[i][j] == '#':
                m += 1
        if m == K:
            ans += 1

        m = n

print(ans)