Problem:


Score : 300 points

Problem Statement

Joisino is planning to open a shop in a shopping street.

Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods.

There are already N stores in the street, numbered 1 through N.

You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2.

Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}.

Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.

Constraints

1≤N≤100

0≤F_{i,j,k}≤1

For every integer i such that 1≤i≤N, there exists at least one pair (j,k) such that F_{i,j,k}=1.

-10^7≤P_{i,j}≤10^7

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
F_{1,1,1} F_{1,1,2} ... F_{1,5,1} F_{1,5,2}
:
F_{N,1,1} F_{N,1,2} ... F_{N,5,1} F_{N,5,2}
P_{1,0} ... P_{1,10}
:
P_{N,0} ... P_{N,10}

Output

Print the maximum possible profit of Joisino's shop.

Sample Input 1

1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2

Sample Output 1

8

If her shop is open only during the periods when Shop 1 is opened, the profit will be 8, which is the maximum possible profit.

Sample Input 2

2
1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1

Sample Output 2

-2

Note that a shop must be open during at least one period, and the profit may be negative.

Sample Input 3

3
1 1 1 1 1 1 0 0 1 1
0 1 0 1 1 1 1 0 1 0
1 0 1 1 0 1 0 1 0 1
-8 6 -2 -8 -8 4 8 7 -6 2 2
-9 2 0 1 7 -5 0 -2 -6 5 5
6 -6 7 -9 6 -5 8 0 -9 -7 -7

Sample Output 3

23



Sample input:
1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2


Sample output:
8

Submission status: Accepted

Solution code:
N=int(input())
F=[list(map(int,input().split())) for i in range(N)]
P=[list(map(int,input().split())) for i in range(N)]

lst=set()
for i in range(2**10):
    a=(10-len(bin(i)[2:]))*"0"+bin(i)[2:]
    if "1" in a:
        num=0
        for n in range(N):
            count=0
            for m in range(10):
                if F[n][m]==1 and a[m]=="1":
                    count+=1
            num+=P[n][count]
        lst.add(num)


print(max(lst))

Submission status: Accepted

Solution code:
n = int(input())
arr = [list(map(int, input().split())) for i in range(n)]
arm = [list(map(int, input().split())) for j in range(n)]  # 入力
ans = -9999999999  # 最小
for item in range(1, (1<<10)):  # 2 ** 10 == 1024
    fund = 0
    for i in range(n):  # 店の数
        cou = 0  # かぶる数
        for x in range(10):  # 月-金(5) * 2
            if (item >> x) % 2 == 1 and arr[i][x] == 1:  # その時間で被るかどうか
                cou += 1
        fund += arm[i][cou]
    ans = max(ans, fund)  # 最大値更新
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]

ans = -float("inf")
for i in range(1, 2 ** 10):
    res = 0
    for j in range(n):
        cnt = sum([(i >> k & 1) & f[j][k] for k in range(10)])
        res += p[j][cnt]
    ans = max(ans, res)

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N=int(input())
F=[list(map(int,input().split())) for _ in range(N)]
P=[list(map(int,input().split())) for _ in range(N)]
ans=(-1)*float("INF")
for i in range(1,1<<10):
    p=0
    for j in range(N):
        cnt=0
        for k in range(10):
            if 1&i>>k & F[j][k]:
                cnt+=1
        p+=P[j][cnt]
    ans=max(p,ans)
print(ans)

Submission status: Accepted

Solution code:
import itertools

N = int(input())
F = [list(map(int,input().split())) for i in range(N)]
P = [list(map(int,input().split())) for i in range(N)]

#print(F)
#print(P)

ans = -10**10
for v in itertools.product([1,0],repeat=10):
    if v != (0,0,0,0,0,0,0,0,0,0):
        bene = 0
        for i in range(N):
            c = 0
            for j in range(10):
                if v[j] == F[i][j] == 1:
                    c += 1
            bene += P[i][c]
        ans = max(ans,bene)
print(ans)

Submission status: Accepted

Solution code:
state = [0 for x in range(0, 10)]

def next(state):
    new_state = [x for x in state]
    new_state[9] += 1
    for i in range(0, 9):
        if new_state[9 - i] >= 2:
            new_state[9 - i] = 0
            new_state[9 - i - 1] += 1
        else:
            break

    return new_state


n = int(input())

f = list()
for i in range(0, n):
    tmp = list(map(int, input().split(" ")))
    f.append(tmp)

p = list()
for i in range(0, n):
    tmp = list(map(int, input().split(" ")))
    p.append(tmp)

ans = -1000000000
for i in range(0, 2 ** 10 - 1):
    state = next(state)
    v = 0
    for j in range(0, n):
        opens = 0
        for k in range(0, len(state)):
            opens += f[j][k] * state[k]
        v += p[j][opens]
    ans = max(ans, v)

print(ans)

Submission status: Accepted

Solution code:
# bit全探索
N = int(input())
F = [list(map(int,input().split())) for _ in range(N)]
P = [list(map(int,input().split())) for _ in range(N)]
ans = -float('inf')
for i in range(2**10):
    if i == 0: # 全く営業しないパターン
        continue
    profit = 0
    pattern = [0]*10
    for j in range(10):
        if 1 << j & i:
            pattern[j] = 1
    #print(pattern)

    for k in range(N):
        l = sum([pattern[m] == F[k][m] == 1 for m in range(10)])
        # l = 0
        # for m in range(10):
        #     if pattern[m] == F[k][m] == 1:
        #         l += 1

        #print(l)
        profit += P[k][l]
    ans = max(ans,profit)
print(ans)

Submission status: Accepted

Solution code:
# bit全探索
N = int(input())
F = [list(map(int,input().split())) for _ in range(N)]
P = [list(map(int,input().split())) for _ in range(N)]
ans = -float('inf')
for i in range(2**10):
    if i == 0: # 全く営業しないパターン
        continue
    profit = 0
    pattern = [0]*10
    for j in range(10):
        if 1 << j & i:
            pattern[j] = 1
    #print(pattern)

    for k in range(N):
        #l = sum([pattern[m] == F[k][m] == 1 for m in range(10)])
        l = 0
        for m in range(10):
            if pattern[m] == F[k][m] == 1:
                l += 1

        #print(l)
        profit += P[k][l]
    ans = max(ans,profit)
print(ans)

Submission status: Accepted

Solution code:

N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]


ans = -float("inf")

for i in range(2**10):
  cnt = [0] * N
  for j in range(10):
    if (i>>j) & 1:
      for k in range(N):
        if F[k][j] == 1:
          cnt[k] += 1
  
  tmp = 0
  valid = False
  for i in range(N):
    if cnt[i] > 0:
      valid = True
    tmp += P[i][cnt[i]]

  if valid:
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

ans = -10**15
for i in range(1, 2**10):
    tmp = 0
    for k in range(N):
        c = 0
        for j in range(10):
            if (i >> j) & 1 and F[k][j]:
                c += 1
        tmp += P[k][c]
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

ans = -(1<<60)
for bit in range(1, 1<<10): # 2**10
  tmp = 0
  for i in range(N):
    cnt = 0
    for j in range(10):
      if (bit>>j)&1 and F[i][j]:
        cnt += 1
    tmp += P[i][cnt]
  
  if ans<tmp:
    ans = tmp
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
F = []
for i in range(N):
    F.append(list(map(int, input().split())))
P = []
for i in range(N):
    P.append(list(map(int, input().split())))

A = []
def dfs(arr):
    if len(arr) == 10:
        if arr != [0,0,0,0,0,0,0,0,0,0]:
            A.append(arr)
        return
    for i in [0,1]:
        dfs(arr + [i])
dfs([])

ans = -(10**18)
# 10^3 * 10^2 = O(10^5)
for i in range(len(A)):
    tmp = 0
    for j in range(N):
        fac = A[i][0]*F[j][0] + A[i][1]*F[j][1] + A[i][2]*F[j][2] + A[i][3]*F[j][3] + A[i][4]*F[j][4] + A[i][5]*F[j][5] + A[i][6]*F[j][6] + A[i][7]*F[j][7] + A[i][8]*F[j][8] + A[i][9]*F[j][9]
        tmp += P[j][fac]
    ans = max(tmp, ans)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import itertools

def main():
    N = int(input())
    F = [int(input().replace(' ',''),2) for _ in range(N)]
    P = [list(map(int,input().split())) for _ in range(N)]
    answer = -float('inf')

    for bit in range(1,1<<10):
        tmp_profit = 0
        for i in range(N):
            count = format(bit&F[i],'b').count("1")
            tmp_profit += P[i][count]
        answer = max(answer,tmp_profit)
    print(answer)
    return 

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc080/tasks/abc080_c
# 普通にbit全探索では？

N = int(input())
F = []
for _ in range(N):
    F.append(list(map(int, input().split())))
P = []
for _ in range(N):
    P.append(list(map(int, input().split())))

bitlen = 10


# def ret_score(n: int):
#     # 営業時間かぶり計算
#     C = []
#     for i in range(N):  # Nでiter
#         cnt = 0
#         for bit in range(bitlen):  # 桁とFを対応
#             if ((n >> bit) & 1) and F[i][bit]:  # もし1その桁で1なら
#                 cnt += 1
#         C.append(cnt)

#     # スコア計算
#     ret = 0
#     for i, c in enumerate(C):
#         ret += P[i][c]
#     return ret


# ans = -10**10
# for n in range(1, 1 << bitlen):
#     ans = max(ans, ret_score(n))
# print(ans)


# numpyでも実装してみる
import numpy as np
F = np.array(F)
P = np.array(P)

bitshifter = np.array([x for x in range(bitlen)])


def ret_score(n: int, F, bitshifter, P):
    bit_arr = (n >> bitshifter) & 1
    F_matched = bit_arr & F
    C = F_matched.sum(axis=1)

    # スコア計算
    ret = 0
    for i, c in enumerate(C):
        ret += P[i, c]
    return ret


ans = -10**10
for n in range(1, 1 << bitlen):
    ans = max(ans, ret_score(n, F, bitshifter, P))
print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc080/tasks/abc080_c
# 普通にbit全探索では？

N = int(input())
F = []
for _ in range(N):
    F.append(list(map(int, input().split())))
P = []
for _ in range(N):
    P.append(list(map(int, input().split())))

bitlen = 10


# def ret_score(n: int):
#     # 営業時間かぶり計算
#     C = []
#     for i in range(N):  # Nでiter
#         cnt = 0
#         for bit in range(bitlen):  # 桁とFを対応
#             if ((n >> bit) & 1) and F[i][bit]:  # もし1その桁で1なら
#                 cnt += 1
#         C.append(cnt)

#     # スコア計算
#     ret = 0
#     for i, c in enumerate(C):
#         ret += P[i][c]
#     return ret


# ans = -10**10
# for n in range(1, 1 << bitlen):
#     ans = max(ans, ret_score(n))
# print(ans)


# numpyでも実装してみる
import numpy as np
F = np.array(F)
P = np.array(P)

bitshifter = np.array([x for x in range(bitlen)])


def ret_score(n: int):
    bit_arr = (n >> bitshifter) & 1
    F_matched = bit_arr & F
    C = F_matched.sum(axis=1)

    # スコア計算
    ret = 0
    for i, c in enumerate(C):
        ret += P[i, c]
    return ret


ans = -10**10
for n in range(1, 1 << bitlen):
    ans = max(ans, ret_score(n))
print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc080/tasks/abc080_c
# 普通にbit全探索では？

N = int(input())
F = []
for _ in range(N):
    F.append(list(map(int, input().split())))
P = []
for _ in range(N):
    P.append(list(map(int, input().split())))

bitlen = 10


def ret_score(n: int):
    # 営業時間かぶり計算
    C = []
    for i in range(N):  # Nでiter
        cnt = 0
        for bit in range(bitlen):  # 桁とFを対応
            if ((n >> bit) & 1) and F[i][bit]:  # もし1その桁で1なら
                cnt += 1
        C.append(cnt)

    # スコア計算
    ret = 0
    for i, c in enumerate(C):
        ret += P[i][c]
    return ret


ans = -10**10
for n in range(1, 1 << bitlen):
    ans = max(ans, ret_score(n))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

opening_status = []
for _ in range(n):
    F = input().replace(' ', '')
    opening_status.append(int(F, 2))

scores = []
for _ in range(n):
    score = list(map(int, input().split()))
    scores.append(score)


ans = -float('INF')
for pattern in range(1, 2**10):
    candidate = 0
    for idx, status in enumerate(opening_status):
        together = pattern & status
        count = sum([1 if together >> i & 1 else 0 for i in range(10)])
        candidate += scores[idx][count]

    ans = max(ans, candidate)

print(ans)

Submission status: Accepted

Solution code:
import itertools 

n = int(input())
#shopの営業データ
shopData = []
#得点ドンぐらいとれるか
point = []
for i in range(n):
    shopData.append(list(map(int, input().split())))
for i in range(n):
    point.append(list(map(int, input().split())))
#最大値
data = list(itertools.product(range(2), repeat = 10))
del data[0]
max_point = - (10 ** 9)
for shop in data:
    cand = 0
    for i in range(len(shopData)):
        count = 0
        for j in range(10):
            if shop[j] == 1 and shopData[i][j] == 1:
                count += 1
        cand += point[i][count]
    max_point = max(max_point, cand)
print(max_point)

Submission status: Accepted

Solution code:

def calc_money(open_time,F,P):
    money = 0
    for i in range(len(F)):
        overlap_time=0
        for j in range(len(open_time)):
            overlap_time+= open_time[j]*F[i][j]
        #overlap_time = sum(list(map(lambda x, y:x*y,zip(open_time,F[i]))))
        money+=P[i][overlap_time]
    return money


        


def main():
    N = int(input())
    F = []
    for i in range(N):
        F.append(list(map(int,input().split())))
    P = []
    for i in range(N):
        P.append(list(map(int,input().split())))

    max_money=0
    for i in range(1024):
        if i==0: continue
        num=str(bin(i))[2:]
        open_time = []

        for j in range(10-len(num)):
            open_time.append(0)
        for j in range(len(num)):
            open_time.append(int(num[j]))
        money = calc_money(open_time,F,P)
        if i==1:
            max_money=money
        elif max_money<money:
            max_money=money
    print(max_money)
            


main()

Submission status: Accepted

Solution code:
N=int(input())
F=[int(input().replace(' ',''),2) for _ in range(N)]
P=[tuple(map(int,input().split())) for _ in range(N)]

ans=-(10**7*N)
for o in range(1,1<<10):
    p=0
    for i in range(N):
        p+=P[i][bin(F[i]&o).count('1')]
    ans=max(ans,p)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
F=[tuple(map(int,input().split())) for _ in range(N)]
P=[tuple(map(int,input().split())) for _ in range(N)]

ans=-(10**7*N)
#営業パターンを10bitの整数であらわす(0はない)
for o in range(1,1<<10):
    #同時に営業する時間帯数のリスト
    C=[0]*N
    for t in range(10):
        #時間帯tに営業するか
        if o&1:
            for i in range(N):
                if F[i][t]==1:
                    C[i]+=1
        o>>=1
    #利益を計算
    p=0
    for i in range(N):
        p+=P[i][C[i]]
    ans=max(ans,p)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
f=[]
p=[]
for i in range(n):
    f.append(list(map(int,input().split())))
for i in range(n):
    p.append(list(map(int,input().split())))
pmax=0
cnt=1024
for i in range(1023):
    cnt+=1
    tmpp=[]
    oc=str(bin(cnt))[3:]
    for j in range(n):
        c=0
        for k in range(10):
            if f[j][k]==1 and oc[k]=="1":
                c+=1
        tmpp.append(p[j][c])
    if i==0:
        pmax=sum(tmpp)
    else:
        if sum(tmpp)>pmax:
            pmax=sum(tmpp)
print(pmax)

Submission status: Accepted

Solution code:
n = int(input())
fl = []
for _ in range(n):
   f = list(map(int,input().split()))
   fl.append(f)
pl = []
for _ in range(n):
   p = list(map(int,input().split()))
   pl.append(p)

ans = -float("inf")
n = 10  # すき間の個数
for i in range(2 ** n):
   if i == 0:
      continue
   bit = [0] * n
   for j in range(n):
       if ((i >> j) & 1):
           bit[j] = 1
   tmp = 0
   for idx,f in enumerate(fl):
      point = 0
      for j in range(n):
         if f[j] == 1 and bit[j] == 1:
            point += 1
      tmp += pl[idx][point] 
   ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import combinations as combi
input = sys.stdin.readline
N = int(input())
f = [list(map(int, input().split())) for _ in range(N)]
p = [list(map(int, input().split())) for _ in range(N)]
days = [i for i in range(10)]
res = -float("inf")
for x in range(1, 11):
  for c in combi(days, x):
    t = 0
    y = [0] * N
    for i in range(N):
      for j in c:
        if f[i][j]:
          y[i] += 1
      t += p[i][y[i]]
    #print(c, t, y)
    res = max(res, t)
print(res)

Submission status: Accepted

Solution code:
N = int(input())
F = []
P = []
for i in range(N):
    a = list(map(int,input().split()))
    c = 0
    for i in range(10):
        c += a[i]*(2**(9-i))
    F.append(c)
for i in range(N):
    P.append(list(map(int,input().split())))
ans = []
for i in range(1,2**10):
    an = 0
    for j in range(len(F)):
        count = 0
        for k in range(10):
            if ((i&F[j]) >> k) & 1 == 1:
                count += 1
        an += P[j][count]
    ans.append(an)
print(max(ans))

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def count_one(bit):
    n = 0
    while bit:
        n += (1 & bit)
        bit = bit >> 1
    return n

def main():
    N = I()
    F_bit = []
    P = []
    ans = -inf
    for i in range(N):
        f = LS()
        f_bit = int(''.join(f), base=2)
        F_bit.append(f_bit)

    for _ in range(N):
        p = LI()
        P.append(p)

    for bit in range(1, 1<<10):
        cur_ans = 0
        for i in range(N):
            i_bit = F_bit[i]
            ci = count_one(bit & i_bit)
            cur_ans += P[i][ci]
        ans = max(ans, cur_ans)
    print(ans)

    '''
    for i in range(N):
        n_open = n_open_time[i]
        i_max_prof = -1
        ix_max_prof = 0
        for j in range(n_open+1):
            if i_max_prof <= P[i][j]:
                i_max_prof = P[i][j]
                ix_max_prof = j
        cur_ans += i_max_prof
        selected_ix.add(ix_max_prof)
        if n_open > 0:
            least_ans = max(least_ans, max(P[i][1:n_open+1]))
    if len(selected_ix) == 1 and 0 in selected_ix:
        print(least_ans)
    else:
    '''

main()

Submission status: Accepted

Solution code:
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]


ans = -1000000009
for i in range(1, 2 ** 10):
        tmp = 0
        check = [0] * N
        for j in range(10):
                if ((i >> j) & 1):
                        for k in range(N):
                                if F[k][j]:
                                        check[k] += 1
        for k in range(N):
                tmp += P[k][check[k]]
        ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
F = [list(map(int,input().split())) for i in range(n)]
P = [list(map(int,input().split())) for i in range(n)]
ans = - 10 ** 15

for i in range(1,2**10):
    tmplist = [0] * n
    tmp = 0
    for j in range(10):
        if (i >> j) & 1:
            for k in range(n):
                if F[k][j] == 1:
                    tmplist[k] += 1
    for j in range(n):
        #print(j, tmplist[j])
        tmp += P[j][tmplist[j]]
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
F = []
P = []

for i in range(N):
  f = list(map(int,input().split()))
  F.append(f)
  
for i in range(N):
  p = list(map(int,input().split()))
  P.append(p)
  
value = 0

ans = - (10 ** 9)

def recur(list):
  con = len(list)
  #list = [0,0, ... ~ 0] ~ [1,1, ... ~ 1]
  if con == 10:
    #1がない = 出店していない場合は何も返さない
    if list.count(1) == 0:
      return
    value = 0
    #インデックス番号とF[i] = 店の出店リストを取得
    for n,shop in enumerate(F):
      con = 0
      for j in range(10):
          #j日に自店が出店し、かつ他店nも出店するならば、カウントする
          if list[j] == 1 and shop[j] == 1:
              con += 1
      #出店リストlistのパターンに応じた店nごとの利益を
      #同時出店日数conから算出し足し合わせる
      value += P[n][con]
 
    global ans
  
    ans = max(ans, value)
    
  else:
    #出店しない
    recur(list + [0])
    #出店する
    recur(list + [1])
    
recur([])
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

answer = []
for i in range(1, 2 ** 10):
  tmp = 0
  for j in range(N):
    cnt = 0
    for k in range(10):
      if (i >> k) & 1 and F[j][k]:
        cnt += 1
    tmp += P[j][cnt]
  answer.append(tmp)
  
print(max(answer))

Submission status: Accepted

Solution code:
n = int(input())

list_1 = []
for i in range(n):
    array = list(map(int, input().split()))
    list_1.append(array)

list_2 = []
for i in range(n):
    array = list(map(int, input().split()))
    list_2.append(array)


num = 2**10
max_ans = -100000000000
for i in range(1, num):
    a = format(i, 'b').zfill(10)
    common_list = [0] * n
    ans = 0
    for j in range(n):
        count = 0
        for k in range(10):
            if list_1[j][k] == int(a[k]) and int(a[k]) == 1:
                count += 1
        ans += list_2[j][count]
    if ans > max_ans:
        max_ans = ans

print(max_ans)

Submission status: Accepted

Solution code:
N=int(input())
F=[list(map(int, input().split())) for i in range(N)]
P=[list(map(int, input().split())) for i in range(N)]

def naiseki(a, b):
  na=len(a)
  nb=len(b)
  if na==nb:
    return sum([a[i]*b[i] for i in range(na)])
  else:
    return None

cand=[]
for i in range(1, 2**10):
  temp=list(map(int, list(format(i, '010b'))))
  rieki=0
  for j in range(N):
    c=naiseki(temp, F[j])
    rieki+=P[j][c]
  cand.append(rieki)
  
print(max(cand))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
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 INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = list2d(N, 10, 0)
for i in range(N):
    A[i] = LIST()
B = list2d(N, 11, 0)
for i in range(N):
    B[i] = LIST()

ans = -INF
# 全時間帯でビット全探索(全0以外)
for S in range(1, 1<<10):
    sm = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            if S & 1<<j and A[i][j]:
                cnt += 1
        sm += B[i][cnt]
    ans = max(ans, sm)
print(ans)

Submission status: Accepted

Solution code:
import sys

*I, = map(int, sys.stdin.read().split())
n = I[0]
f = list(zip(*[iter(I[1:1+10*n])] * 10))
p = list(zip(*[iter(I[1+10*n:])] * 11))

def main():
    res = -float('inf')
    for i in range(1, 2**10):
        cnt = [0] * n
        for j in range(10):
            if i >> j & 1:
                for k in range(n):
                    cnt[k] += f[k][j]
        profit = 0
        for k in range(n):
            profit += p[k][cnt[k]]
        res = max(res, profit)

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

Submission status: Accepted

Solution code:
import sys
import numpy as np 

I = np.array(sys.stdin.read().split(), dtype=np.int64)
n = I[0]
f = I[1:1+10*n].reshape(n, 10)
p = I[1+10*n:].reshape(n, 11)

def main():
    schedules = np.arange(1, 2**10)[:, None] >> np.arange(10) & 1

    res = f & schedules[:, None]
    res = np.sum(res, axis=2)

    res = p[np.arange(n), res]
    res = np.sum(res, axis=1)

    ans = np.amax(res)
    return ans
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A=[0]*N
P=[0]*N


for i in range(N):
    A[i] = list(map(int,input().split()))
for i in range(N):
    P[i] = list(map(int,input().split()))

MAX=-1*(10**9)
for i in range(1,1024):
    t=format(i,"b")
    l=10-len(t)
    t="0"*l+t
    a=[0]*N
    for j in range(10):
        
        if(t[j]=="1"):
            for k in range(N):
                
                if(int(A[k][j])==int(t[j])):
                    a[k]+=1
    T=0
    for j in range(N):
        T+=P[j][a[j]]
    MAX=max(T,MAX)

print(MAX)

Submission status: Accepted

Solution code:
n = int(input())
F = [list(map(int, input().split())) for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(n)]

# print(F)
# print(P)
max_score = -float('inf')

for pattern_i in range(1, 2**10):
  op_num = [0]*n
  for pos_i in range(10):
    if pattern_i & 1<<pos_i:
      for n_i in range(n):
        op_num[n_i] += F[n_i][pos_i]
        
  max_score = max(max_score, sum([p_i[op_num_i] for p_i, op_num_i in zip(P, op_num)]))

print(max_score)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

n=int(input())
F=[list(map(int,input().split()))  for i in range(n)]
P=[list(map(int,input().split()))  for i in range(n)]
ans=-inf
for bit in range(1,2**10):
    count=[0]*n
    for k in range(10):
        if (bit>>k & 1):
            for i,Fi in enumerate(F):
                count[i]+=Fi[k]
    tmp=0
    for i,Pi in enumerate(P):
        tmp+=Pi[count[i]]
    ans=max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
def calc(days):
    if sum(days) == 0:
        return
    profit = 0
    for i in range(N):
        both = 0
        for f, d in zip(F[i], days):
            if f == d == 1:
                both += 1
        profit += P[i][both]
    global ans
    ans = max(ans, profit)


def dfs(days):
    if len(days) == 10:
        calc(days)
        return
    dfs(days + [0])
    dfs(days + [1])


ans = 10 ** 9 * (-1)
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

dfs([])
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
F = []
for i in range(N):
    f = list(map(int, input().split()))
    F.append(f)

P = []
for i in range(N):
    p = list(map(int, input().split()))
    P.append(p)

ans = (-10 ** 7) * 100 * 10

def f(a):
    if a.count(1) == 0:
        return
    prof = 0
    for i, fi in enumerate(F):
        c = 0
        for j in range(10):
            if a[j] == 1 and fi[j] == 1:
                c += 1
        prof += P[i][c]

    global ans
    ans = max(ans, prof)

def dfs(a):
    if len(a) == 10:
        f(a)
    else:
        dfs(a + [0])
        dfs(a + [1])

dfs([])
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    F = []
    for i in range(N):
        f = list(map(int, input().split()))
        F.append(f)

    P = []
    for i in range(N):
        p = list(map(int, input().split()))
        P.append(p)


    B = []
    # 全部0はありえない
    for i in range(1, 2 ** 10):
        b = format(i, 'b').zfill(10)
        B.append(b)

    # print(N)
    # print(F)
    # print(P)
    # print(B)

    profits = []
    for bi in B:
        profit = 0
        for i, fi in enumerate(F):
            c = 0
            for j in range(10):
                if bi[j] == '1' and fi[j] == 1:
                    c += 1
            profit += P[i][c]
        profits.append(profit)
    print(max(profits))





if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
f = [list(map(int,input().split())) for _ in range(n)]
p = [list(map(int,input().split())) for _ in range(n)]
ans = -10**10
for i in range(1,2**10):
    tmp_prof = 0
    test = bin(i)[2:].zfill(10)
    for j in range(n):
        tmp_c = 0
        for k in range(10):
            if (f[j][k]==1) & (test[k]=='1'):
                tmp_c+=1
        tmp_prof += p[j][tmp_c]
    if ans < tmp_prof:
        ans = tmp_prof
print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
F = [LIST() for _ in range(N)]
P = [LIST() for _ in range(N)]

ans = -INF
for i in range(1, 1<<10):
	i = "{:b}".format(i).zfill(10)
	tmp = 0
	for j in range(N):
		cnt = 0
		for k in range(10):
			if int(i[k]) and F[j][k]:
				cnt += 1
		tmp += P[j][cnt]
	ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
f=[0]*n
for i in range(n):
  x=list(map(int,input().split()))
  for j in range(len(x)):
    if x[j]==1:
      f[i]+=1<<j
  
p=[[0 for j in range(10)] for i in range(n)]

for i in range(n):
  p[i]=list(map(int,input().split()))

ans=10**9*(-1)-1
for i in range(1,2**10):
  pro=0
  for j in range(len(f)):
    open=0
    for k in range(10):
      if (i>>k)&1==1 and (f[j]>>k)&1==1:
        open+=1
    pro+=p[j][open]
  if ans<pro:
    ans=pro
print(ans)