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 k in range(N)]
P = [list(map(int,input().split())) for k in range(N)]
ans = -float("inf")
for k in range(2**10):
    temp = 0
    S = [0 for l in range(N)]
    for s in range(N):
        for d in range(10):
            if (k>>d)&1 == 1:
                if F[s][d] == 1:
                    S[s] += 1
    if sum(S) > 0:
        for l in range(N):
            temp += P[l][S[l]]
        ans = max(ans,temp)

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
f = [[0]*10 for _ in range(n)]
p = [[0]*10 for _ in range(n)]
for i in range(n):
    f[i]  = list(map(int,input().split()))
for i in range(n):
    p[i]  = list(map(int,input().split()))
ans = - 10**9 -1 
for i in range(1,1024):
    rev = 0
    for j in range(n):# 時間帯jに関して何個かぶってるか
        cnt = 0#一致する店数
        for k in range(10):# 店k との一致する営業時間
            if 2**k & i and f[j][k]:#両方１なら開店
                cnt  += 1
        #print(cnt,j)
        rev += p[j][cnt]
    ans = max(rev,ans)
print(ans)

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    fre=[int(''.join(input().split()),2) for i in range(n)]
    pay=[list(map(int,input().split())) for i in range(n)]
    
    ans=-10**9
    for bit in range(1,1<<10):
        money=0
        for i in range(n):
            cnt=format(bit&fre[i],'b').count('1')
            money+=pay[i][cnt]
        ans=max(money,ans)
    print(ans)
if __name__=='__main__':
    main()

Submission status: Accepted

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

ans = float('-inf')
for i in range(1, 2**10):
    flags = [0] * 10
    for i, c in enumerate(bin(i)[2:][::-1]):
        if c == "1":
            flags[i] = 1

    res = 0
    for f, p in zip(F, P):
        cnt = 0
        for x, y in zip(f, flags):
            if x & y:
                cnt += 1
        res += p[cnt]
    ans = max(ans, res)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
F = [int(input().replace(' ',''), 2) for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(n)]
ans=-10**10
for sp in range(1, 1024):
  total = 0
  for i in range(n):
    b = bin(F[i] & sp)
    total += P[i][b.count('1')]
  ans = max(ans, total)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
F = [int(input().replace(' ',''), 2) for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(n)]
ans=-10**7*n
for sp in range(1, 2**10):
  total = 0
  for i in range(n):
    total += P[i][bin(F[i] & sp).count('1')]
  ans = max(ans, total)
print(ans)

Submission status: Accepted

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

ans = -10**9

for bit in range(1 << 10):
  if bit == 0:
    continue

  total = 0

  for n in range(N):
    count = 0

    for i in range(10):
      if bit & (1 << i):
        count += F[n][i]
    total += P[n][count]

  if total > ans:
    ans = total

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
SO=[int(input().replace(' ',''), 2) for i in range(N)]
PT=[list(map(int,input().split())) for i in range(N)]
ret=-10**7*N
for sp in range(1,2**10):
  r=0
  for i in range(N):
    r+=PT[i][bin(SO[i] & sp).count('1')]
  ret=max(ret,r)
print(ret)

Submission status: Accepted

Solution code:
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)

    from collections import Counter
    from collections import deque

    #dxy = [[0,1],[0,-1],[1,0],[-1,0]]
    #dxy = [[0,1],[0,-1],[1,0],[-1,0],[1,1],[1,-1],[-1,1],[-1,-1]]
    #mod = 1000000007

    n = int(input())
    F = [input().split() for _ in range(n)]
    P = [list(map(int, input().split())) for _ in range(n)]
    ans = -10**10
    for i in range(1, 1033):
        a = list(str(format(i, '010b')))
        total = 0
        for j in range(n):
            cnt = 0
            for k in range(10):
                if F[j][k]=='1' and a[k]=='1':
                    cnt += 1
            total += P[j][cnt]
        if total>ans:
            ans = total
    print(ans)




if __name__ == '__main__':
    main()

Submission status: Accepted

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

from itertools import *
first=True
ans=-10**12
for tmp in list(product([0,1], repeat=10)):
    if first:
        first=False
        continue
    sm=0
    for i in range(n):
        cnt=0
        for j in range(10):
            cnt+= tmp[j] & f[i][j]
        sm+=p[i][cnt]
    if ans < sm:
        ans=sm
print(ans)

Submission status: Accepted

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

from itertools import *
first=True
ans=-10**12
for tmp in list(product([0,1], repeat=10)):
    if first:
        first=False
        continue

    ona=[]
    for mise in f:
        cnt=0
        for j in range(10):
            cnt+= tmp[j] & mise[j]
        ona.append(cnt)

    sm=0
    for i in range(len(p)):
        sm+=p[i][ona[i]]
    if ans < sm:
        ans=sm
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np

def read():
    return sys.stdin.readline().rstrip()

def main():
    n = int(read())
    f = np.array([[int(i) for i in read().split()] for _ in range(n)])
    p = [[int(i) for i in read().split()] for _ in range(n)]
    pf = -float("inf")
    for i in range(1, 2**10):
        t = 0
        g = np.array([i >> j & 1 for j in range(10)])
        for j in range(n):
            t += p[j][(f[j] & g).sum()]
        pf = max(t, pf)
    print(pf)

if __name__ == '__main__':
    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=-10**18
for i in range(1,2**10):
  d=0
  for j in range(n):
    cnt=0
    for k in range(10):
      if i>>k&1==f[j][k]==1:
        cnt+=1
    d+=p[j][cnt]
  ans=max(ans,d)
print(ans)

Submission status: Accepted

Solution code:
import itertools
j_shop = list(set(itertools.product(*[[0, 1]]*10)) - set([tuple([0]*10)]))

n = int(input())

D = [[] for _ in range(10)]
from collections import defaultdict
profit = defaultdict(int)


for i in range(n):
    f = list(map(int, input().split()))
    for j in range(10):
        if f[j] == 1:
            D[j].append(i)
            
for i in range(n):
    p = list(map(int, input().split()))
    for j in range(11):
        profit[(i, j)] = p[j]
        
ans = float('-INF')
for js in j_shop:
    temp = [0]*n
    for i in range(10):
        if js[i] == 1:
            for d in D[i]:
                temp[d] += 1
    p = 0
    for k, v in enumerate(temp):
        p += profit[(k, v)]
    ans = max(ans, p)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
from itertools import product

n,*fp = map(int,open(0).read().split())
f = np.array([fp[i*10:(i+1)*10] for i in range(n)])
p = np.array([fp[(n*10+i*11):(n*10+(i+1)*11)] for i in range(n)])

op_list  = np.array(list(product([0,1],repeat=10)))[1:]
op_count = np.dot(op_list,f.T)
ans = p[np.arange(n),op_count].sum(axis=1).max()
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
f=[]
p=[]
for i in range(n):
    f_i=list(map(int,input().split()))
    f.append(f_i)
for i in range(n):
    p_i=list(map(int,input().split()))
    p.append(p_i)
ans=-10000000*n
for i in range(1,1024):
    i_bin=((bin(i))[2:]).zfill(10)
    temp=0
    for j in range(n):
        buf=0
        for k in range(10):
            if f[j][k]==1 and i_bin[k]=="1":
                buf+=1
        temp+=p[j][buf]
    if ans<temp:
        ans=temp
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
F=[int(input().replace(' ',''),2) for i in range(N)]
P=[list(map(int,input().split())) for i in range(N)]
print(max(sum([p[bin(f&i).count('1')] for f,p in zip(F,P)]) for i in range(1,2**10)))

Submission status: Accepted

Solution code:
def main():
    SHOP_NUM = int(input())
    open_info = [input().split() for _ in range(SHOP_NUM)]
    profit = [list(map(int, input().split())) for _ in range(SHOP_NUM)]
    answer = -float("inf")
    for i in range(1, 1024):
        open = str(format(i, '10b'))
        now_profit = 0
        for shop in range(SHOP_NUM):
            tmp = 0
            for j in range(10):
                if open[j] == "1" and open_info[shop][j] == "1":
                    tmp += 1
            now_profit += profit[shop][tmp]
        answer = max(answer, now_profit)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
import sys
sys.setrecursionlimit(3000)
n = int(input())
f = np.array([list(map(int, input().split())) for _ in range(n)])
p = np.array([list(map(int, input().split())) for _ in range(n)])


def dfs(a):
    if len(a) == 10:
        if sum(a) == 0:
            return -10**9
        else:
            profit = 0
            for i in range(n):
                c = int(np.dot(a, f[i]))
                profit += p[i][c]
            return profit

    ret1 = dfs(np.append(a, 1))
    ret2 = dfs(np.append(a, 0))
    return max(ret1, ret2)


start = np.array([])
print(dfs(start))

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc080/tasks/abc080_c

# 各店の各曜日の各営業時間で営業するかどうか全探索


N = int(input())    # 店の数
F_list = []
for _ in range(N):
    f = list(map(int, input().split()))
    F_list.append(f)

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

# # 各曜日時間帯の最低限の店の開店数（おねーちゃんの店を考慮しない）
# min_open_list = []
# for i in range(10):
#     count_open = 0
#     for j in range(N):
#         if F_list[j][i] == 1:
#             count_open += 1
#     min_open_list.append(count_open)

# c個の店が営業中の時の、店iの利益
def benefit(i, c):
    return P_list[i][c]

is_joisino_shop_open_list = [False] * 10
benefit_joisino_list = []

def dfs(j):
    if j >= 10:

        # 1つ以上の時間帯でお店を営業していること
        if True in is_joisino_shop_open_list:
            # joisinoおねえちゃんのお店の利益を計算
            benefit_joisino = 0
            for n in range(N):
                # 各お店ごとのjoisinoお姉ちゃんの利益を計算
                count_n_open = 0                
                shop_n_list = F_list[n]

                for i in range(10):    
                    if shop_n_list[i] == 1 and is_joisino_shop_open_list[i] == True:
                        count_n_open += 1

                benefit_n_joisino = P_list[n][count_n_open]
                benefit_joisino += benefit_n_joisino

            benefit_joisino_list.append(benefit_joisino)

        return

    # joisinoお姉ちゃんのお店をあけるかあけないか全パターン試す
    # j番目の日時にjoisinoお姉ちゃんのお店をあけるとき
    is_joisino_shop_open_list[j] = True
    dfs(j+1)

    # j番目の日時にjoisinoお姉ちゃんのお店をあけないとき
    is_joisino_shop_open_list[j] = False
    dfs(j+1)


dfs(0)
max_benefit_joisino = max(benefit_joisino_list)
print(max_benefit_joisino)

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)]

#%%
INF = 1<<60
ans = -INF
for st in range(1,1<<10):
    t = st
    state = [0]*10
    for i in range(10):
        state[i] = t%2
        t >>= 1
    
    cur = 0
    for k in range(N):
        tmp = 0
        for i in range(10):
            if F[k][i] == 1 and state[i] == 1:
                tmp += 1
        cur += P[k][tmp]
    
    ans = max(ans,cur)

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)]

f2 = []
ans = -10**10

for i in f:
    f_tmp = ''
    for j in i:
        f_tmp += str(j)
    f2.append(f_tmp)

li = []

def bfs():
    global li
    if len(li) == 10:
        hantei()
    else:
        li.append(0)
        bfs()
        li.pop(-1)
        li.append(1)
        bfs()
        li.pop(-1)

def hantei():
    global li,ans
    if 1 not in li:
        pass
    else:
        li_tmp = ''
        ans_tmp = 0
        for i in li:
            li_tmp += str(i)
        tmp = format(int(li_tmp, 2) & int(f2[0], 2), 'b')

        for i in range(n):
            tmp = format(int(li_tmp, 2) & int(f2[i], 2), 'b')
            ans_tmp += p[i][tmp.count('1')]

        ans = max(ans, ans_tmp)

bfs()

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
F=[[0]*10]*N
ans=-10e+9
for i in range(N):
    F[i]=list(map(int,input().split()))
    
P=[[0]*10]*N
for i in range(N):
    P[i]=list(map(int,input().split()))

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
F=[[0]*10]*N
ans=-10e+9
for i in range(N):
    F[i]=list(map(int,input().split()))
    
P=[[0]*10]*N

for i in range(N):
    P[i]=list(map(int,input().split()))
SUM=[["" for i in range(10)] for i in range(N)]
for i in range(N):
    tm=0
    for j in range(10):
        tm+=P[i][j]
        SUM[i][j]=tm


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

print(ans)

Submission status: Accepted

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

ans = -10000000000
for i in range(1, 2 ** 10):
    sum = 0
    for j, f in enumerate(F):
        cover = i & f
        cnt = 0
        while cover != 0:
            if cover % 2 == 1:
                cnt += 1
            cover //= 2
        sum += P[j][cnt]
    ans = max(sum, ans)

print(ans)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
f = [list(map(int,input().split())) for _ in range(n)]
p = [list(map(int,input().split())) for _ in range(n)]
INF = float("inf")
ans = -INF
for i in list(itertools.product([0,1],repeat=10)):
  tmp = 0
  if sum(i)==0: continue
  for j in range(n):
    open_s = sum([1 for p,q in zip(i,f[j]) if p+q==2])
    tmp += p[j][open_s]
  ans = max(tmp,ans)
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np

# N 店の数
n = int(input())

# F 店の営業計画
f = [input().replace(" ", "") for i in range(n)]

# P 営業利益
p = [list(map(int, input().split())) for i in range(n)]

p_max = -999999999999999
for i in range(1, 1024):
    f_b = format(i, '010b')
    p_10 = 0
    for f_1, p_1 in zip(f, p):
        p_cnt = 0
        for j in range(10):
            if f_1[j] == '1' and f_b[j] == '1':
                p_cnt += 1
        p_10 += p_1[p_cnt]
    if p_10 > p_max:
        if p_10 == 0:
            print(str(i))
            break
        p_max = p_10

print(p_max)

Submission status: Accepted

Solution code:
from itertools import product

def solve(n, FF, PP):
    return max(
        sum(P[sum(i & f for i, f in zip(I, F))] for F, P in zip(FF, PP))
        for I in list(product(range(2), repeat=10))[1:]
    )

_n = int(input())
_FF = [list(map(int, input().split())) for _ in range(_n)]
_PP = [list(map(int, input().split())) for _ in range(_n)]
print(solve(_n, _FF, _PP))

Submission status: Accepted

Solution code:
n = int(input())

f = list()
for i in range(n):
    temp = list(map(str, input().split()))
    bin_str = ''
    for j in range(10):
        bin_str = bin_str + temp[j]

    f.append(int(bin_str, 2))

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

max_sell = -10**10
open = 0
for i in range(2**10):
    temp_sell = 0

    open_list = '{:010b}'.format(open)
    open_flag = False
    check = 0
    for j in range(5):
        check = int(open_list[j * 2]) + int(open_list[j * 2 + 1])
        if(check > 0):
            open_flag = True
            break

    if(open_flag):
        for j in range(n):
            res_temp = open & f[j]
            count = bin(res_temp).count('1')

            temp_sell += p[j][count]

        if(temp_sell > max_sell):
            max_sell = temp_sell

    open += 1

print(max_sell)

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**9)

"""
自分の店が開く時間帯の組み合わせを用意する.itertools?
その組み合わせの時間帯に営業している店を調べる。for文
店ごとにciをカウントしていく.for文
最後にansに店ごとのPを加算していき、マックスの値を調べる。ans = max(ans,~)
"""
#開いてる時間帯を1、開いてない時間帯を0とすると組み合わせは2**10通り
for i in range(2**10):
    check = [0]*10
    tmp = 0
    for j in range(10):
        if (i>>j)&1: #10個の時間帯で開いてる時間帯を探す
            check[j] = 1
    if any(check)==False:
        continue
    for k in range(N):
        cnt = 0 #同時間帯に営業している数
        for l in range(10):
            if F[k][l] == 1 and check[l] == 1:
                cnt += 1
        tmp += P[k][cnt]
    ans = max(ans,tmp)

print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
lst1 = [list(map(int,readline().split())) for i in range(n)]

lst2 = [list(map(int,readline().split())) for i in range(n)]

#曜日、時刻にどの店が営業しているかを埋め込む
lst3 = [[] for _ in range(10)]
for i in range(n):
    for j in range(10):
        if lst1[i][j] == 1:
            lst3[j].append(i)

#ビット全探索
def bit_search(lst):
    keta = len(lst)
    bit_lst = []
    for i in range(2**keta):
        sub = [0]*n
        for j in range(keta):
            if ((i>>j) &1):
                for k in lst3[j]:
                    sub[k] += 1
        bit_lst.append(sub)
    return bit_lst


dummy = [0]*(10)
all_lst = bit_search(dummy)

ans = -10**9
for i in all_lst[1:]:
    res = 0
    for j in range(n):
        res += lst2[j][i[j]]
    ans = max(res,ans)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=[[int(i) for i in input().split()] for i in range(n)]
b=[[int(i) for i in input().split()] for i in range(n)]
maxi=-10**9
check=[0]*10
for i in range(2**10):
    check=[0]*10
    tmp=0
    for j in range(10):
        if (i>>j)&1:
            check[j]=1
    if any(check)==False:
        continue
    for i in range(n):
        cnt=0
        for j in range(10):
            if a[i][j]==1 and check[j]==1:
                cnt+=1
        tmp+=b[i][cnt]
    if tmp>maxi:
        maxi=tmp
print(maxi)

Submission status: Accepted

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

import itertools as it

stat = [i for i in it.product([0, 1], repeat=10)]
stat.pop(0)
ans = -10**9
for t_stat in stat:
    x = 0
    for i in range(n):
        tmp=[min(j, k) for j, k in zip(t_stat, s[i])]
        lll=tmp.count(1)
        x+=p[i][lll]
    ans = max(ans, x)
print(ans)

Submission status: Accepted

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

import itertools
D=list(itertools.product([0,1],repeat=10))

ans=(-1)*9999999999
for i in D:
  a=0
  if i!=(0,0,0,0,0,0,0,0,0,0):
    for j in range(N):
      b=0
      for k in range(10):
        if i[k]==1 and A[j][k]==1:
          b+=1
      a+=B[j][b]
    ans=max(ans,a)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
f = []
p = []
ans = []
for i in range(n):
    f.append(list(map(int, input().split())))
for i in range(n):
    p.append(list(map(int, input().split())))
for i in range(1, 2**10):
    b = format(i, '#012b')[2:]
    s = 0
    for j in range(n):
        s2 = 0
        for k in range(10):
            s2 += int(b[k])*f[j][k]
        s += p[j][s2]
    ans.append(s)
print(max(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)]

result = -float('inf')
for i in range(1, 1024):
    t = 0
    for j in range(N):
        c = 0
        for k in range(10):
            c += (i >> k & 1) & F[j][k]
        t += P[j][c]
    result = max(result, t)
print(result)

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)]

result = -float('inf')
for i in range(1, 1024):
    t = 0
    for j in range(N):
        t += P[j][sum((i >> k & 1) & F[j][k] for k in range(10))]
    if t > result:
        result = t
print(result)

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 = -int(1e09)
for i in range(1,1 << 10):
    m = [0] * N
    for j in range(10):
        if(i >> j & 1):
            for k in range(N):
                if F[k][j] == 1:
                    m[k] += 1
    l = 0
    for j in range(N):
        l += P[j][m[j]]
    ans = max(ans,l)
print(ans)

Submission status: Accepted

Solution code:
TIMEZONE_NUM = 10

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())))

ans = -float('inf')
for i in range(1, 2 ** TIMEZONE_NUM):
    tmp_ans = 0
    for n in range(N):
        both_open_num = 0
        for flag_j, flag_f in zip(bin(i)[2:].zfill(TIMEZONE_NUM), F[n]):
            if int(flag_j) == flag_f == 1:
                both_open_num += 1
        tmp_ans += P[n][both_open_num]
    ans = max(ans, tmp_ans)

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
F = []
for _ in range(N):
    F.append([str(x) for x in input().split()])
P = []
for _ in range(N):
    P.append([int(x) for x in input().split()])
ans = -10 ** 10
for i in range(1, 2 ** 10):
    bini = "0b" + format(i, 'b').zfill(10)
    ans_ = 0
    for j in range(N):
        shop = "0b" + "".join(F[j])
        cnt = bin((int(shop, 2) & int(bini, 2))).count("1")
        ans_ += P[j][cnt]
    ans = max(ans, ans_)
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
F = []
for _ in range(N):
    F.append([int(x) for x in input().split()])
P = []
for _ in range(N):
    P.append([int(x) for x in input().split()])
ans = -10 ** 10
import numpy as np
for i in range(1, 2 ** 10):
    bini = format(i, 'b').zfill(10)
    bini = np.array([int(x) for x in list(bini)])
    ans_ = 0
    for j in range(N):
        shop = np.array(F[j])
        cnt = np.count_nonzero(shop * bini)
        ans_ += P[j][cnt]
    ans = max(ans, ans_)
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)]
d = 10
status = []
for mask in range(1 << d):
    tmp = []
    for i in range(d):
        tmp.append((mask >> i) & 1)
    status.append(tmp)
# print(status)
ans = -10**12
for i in range(1, 1 << d):
    tmp = 0
    # print(status[i])
    # status[i]と同じところにビットが立っている個数をカウントする
    for j in range(N):
        cnt = 0
        for shop_status, joisino_status in zip(F[j], status[i]):
            if shop_status == 1 and joisino_status == 1:
                cnt += 1
        tmp += P[j][cnt]
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from itertools import permutations

def main():
    n = int(input().strip())
    f = [0] * n
    p = [[] for _ in range(n)]
    for i in range(n):
        tmp = list(map(int, input().strip().split()))
        for j in range(10):
            f[i] += tmp[9-j] << j
    for i in range(n):
        p[i] = list(map(int, input().strip().split()))
    ans = -INF
    for b in range(1, 2**10):
        m = 0
        for j in range(n):
            v = fun(f[j], b)
            m += p[j][v]
        ans = max(ans, m)
    print(ans)

def fun(f, q):
    ans = 0
    r = f & q
    for i in range(10):
        ans += (r >> i) & 0x1
    return ans

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    F = []
    for _ in range(N):
        F.append([int(x) for x in input().split()])

    P = []
    for _ in range(N):
        P.append([int(x) for x in input().split()])


    ans = -float("inf")
    for i in range(1, 2 ** 10):
        c = [0] * N
        for j in range(10):
            if i >> j & 1:
                for k in range(N):
                    if F[k][j] == 1:
                        c[k] += 1

        tmp = 0
        for k in range(N):
            tmp += P[k][c[k]]

        ans = max(ans, tmp)

    print(ans)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from operator import mul

n = int(input())
cof = [1 << x for x in range(10)]
fs = [sum(map(mul, map(int, input().split()), cof)) for _ in range(n)]
ps = [list(map(int, input().split())) for _ in range(n)]

ans = float('-inf')
for g in range(1, 1024):
   ans = max(ans, sum(p[bin(f & g).count('1')] for f, p in zip(fs, ps)))

print(ans)

Submission status: Accepted

Solution code:
import sys
bbn=1000000007
	
#+++++

class store:
	def __init__(self, is_open):
		ret=0
		for i,v in enumerate(is_open):
			ret += (2**i)*v
		self.is_open=ret
	
	def add_proof_info(self,pl):
		self.ploofs=pl
		
	def get_proof(self, time):
		count=0
		temp=self.is_open
		tt=time
		while temp>0:
			count+=1&tt&temp
			tt=tt>>1
			temp=temp>>1
			#print(temp)

		return self.ploofs[count]
		
def main():
	n = int(input())
	stores=[]
	for i in range(n):
		is_open = list(map(int, input().split()))
		st=store(is_open)
		stores.append(st)
		
	for s in stores:
		pl=list(map(int, input().split()))
		s.add_proof_info(pl)
	
	ret=None
	for i in range(1,(2**10)+0):
		value=sum([s.get_proof(i) for s in stores])
		if ret is None or ret < value:
			ret = value
		
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
from itertools import product
from operator import and_
N = int(input())
F = [tuple(map(lambda s: s=="1", input().split())) for _ in range(N)]
P = [tuple(map(int, input().split())) for _ in range(N)]
print(max(sum(P[i][sum(map(and_, F[i], prod))] for i in range(N)) for prod in product((True, False), repeat=10) if sum(prod)))

Submission status: Accepted

Solution code:
n = int(input())
info = [list(map(int, input().split())) for i in range(n)]
profits = [list(map(int, input().split())) for i in range(n)]
ans = -float("inf")

for i in range(1, 2 ** 10):
    tmp = 0
    for j in range(n):
        count = 0
        for k in range(10):
            if ((i >> k) & 1) == 1 and info[j][k] == 1:
                count += 1

        tmp += profits[j][count]
    
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  a=[LI() for _ in range(n)]
  b=[LI() for _ in range(n)]

  ans=-inf
  for i in range(1,1<<10):
    _ans=0
    for _i,x in enumerate(a):
      counter=0
      for j in range(10):
        if i&(1<<j) and x[j]==1:
          counter+=1
      _ans+=b[_i][counter]
    ans=max(ans,_ans)
  return ans

# main()
print(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_list = [0] * (2 ** 10 - 1)
# 開ける時間をbit全探索
for i in range(1, 2**10):
    open_day = [0] * 10
    # 店を開ける時間を調べる
    for j in range(10):
        if i & (1 << j):
            open_day[j] = 1
    # 店k について一緒に開く時間帯の数を調べ，その個数をP[k][count]に入れる
    for k in range(N):
        count = 0
        for t in range(10):
            if open_day[t] == F[k][t] and F[k][t] == 1:
                count += 1
        ans_list[i-1] += P[k][count]

print(max(ans_list))