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: Runtime Error

Solution code:
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

from types import GeneratorType
def bootstrap(func, stack=[]):
    def wrapped_function(*args, **kwargs):
        if stack:
            return func(*args, **kwargs)
        else:
            call = func(*args, **kwargs)
            while True:
                if type(call) is GeneratorType:
                    stack.append(call)
                    call = next(call)
                else:
                    stack.pop()
                    if not stack:
                        break
                    call = stack[-1].send(call)
            return call
 
    return wrapped_function

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

n,m,k = Ri()
lis = []
for i in range(n):
    s = ri()
    lis.append(s)

cnt = [0]
flag = [1]*(n+m)
tot = n+m

@bootstrap
def backtrack(cur,cnt):
    # print(cur)
    if cur == tot:
        tcnt = 0
        row = flag[:n]
        col = flag[n:n*m]
        for i in range(n):
            for j in range(m):
                if row[i] == 1 or col[j] == 1:
                    continue
                elif lis[i][j] == '#':
                    tcnt+=1
        if tcnt == k:
            cnt[0]+=1

        yield 
    
    yield backtrack(cur+1,cnt)
    flag[cur] = 0
    yield backtrack(cur+1,cnt)
    flag[cur] = 1
    yield 

backtrack(0,cnt)
print(cnt[0])

Submission status: Runtime Error

Solution code:
h, v, k = map(int,input().split())
C = []
for i in range(h):
  for j in range(v):
    l = list(map(int,input().split()))
    C.append(l)
    
black_hcounter = []
black_vcounter = []
for i in range(h):
  counter = 0
  for j in range(v):
    if C[i][j] == "#":
      counter += 1
  black_hcounter.append(counter)
sum = sum(black_hcounter)
for j in range(v):
  counter = 0
  for i in range(h):
    if C[i][j] == "#":
      counter += 1
  black_vcounter.append(counter)
  
ans = 0
herasu = sum - k
if k == sum:
  ans = 1
else:
  for i in range(1<<h):
    l = []
    for j in range(h):
        if (i>>j & 1) == 1:
            l.append(a[j])
    if sum(l) == k:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int H, W, K;
	cin >> H >> W >> K;

	vector<string> S(H);
	REP(i, H) cin >> S[i];

	int ret = 0;

	REP(i, 1 << (W + H))
	{
		vector<string> A = S;
		int count = 0;
		REP(j, H){
			if((i >> j) & 0x01){
				REP(k, W) A[j][k] = '*';
			}
		}
		REP(j, W){
			if((i >> (H + j) & 0x01)){
				REP(k, H) A[k][j] = '*';
			}
		}
		REP(r, H){
			REP(c, W) if(A[r][c] == '#') count++;
		}
		if(count == K) ret++;
	}

	cout << ret << endl;


	return 0;
}

Submission status: Runtime Error

Solution code:
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

n,m,k = Ri()
lis = []
for i in range(n):
    s = ri()
    lis.append(s)

cnt = [0]
flag = [1]*(n+m)
tot = n+m

def backtrack(cur,cnt):
    # print(cur)
    if cur == tot:
        tcnt = 0
        row = flag[:n]
        col = flag[n:n*m]
        for i in range(n):
            for j in range(m):
                if row[i] == 1 or col[j] == 1:
                    continue
                elif lis[i][j] == '#':
                    tcnt+=1
        if tcnt == k:
            cnt[0]+=1

        return
    
    backtrack(cur+1,cnt)
    flag[cur] = 0
    backtrack(cur+1,cnt)
    flag[cur] = 1
    return

backtrack(0,cnt)
print(cnt[0])

Submission status: Runtime Error

Solution code:
n = int(input())
S = []
C0 = 0
C1 = 0
C2 = 0
C3 = 0

for i in range(n):
  m = input()
  S.append(m)
  if m == 'AC':
    C0 += 1
  elif m == 'WA':
    C1 += 1
  elif m == 'TLE':
    C2 += 1
  elif m == 'RE':
    C3 += 1
    
print('AC x', C0)
print('WA x', C1)
print('TLE x', C2)
print('RE x', C3)

Submission status: Runtime Error

Solution code:
h+w