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:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    ans = -INF
    for bits in range(1, 1 << 10):
        res = 0
        for i in range(N):
            c = 0
            for j in range(10):
                if F[i][j] and (bits & (1 << j)):
                    c += 1
            res += P[i][c]
        if ans < res:
            ans = res

    print(ans)
    return


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)]
maxp=-float("inf")
for i in range(1,2**10):
  pt=0
  for j in range(n):
    cnt=0
    for k in range(10):
      if (i>>k)&1 and f[j][k]==1:
        cnt+=1
    pt+=p[j][cnt]
  maxp=max(maxp,pt)
print(maxp)

Submission status: Accepted

Solution code:
#coding: utf-8
from itertools import product

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

ret = -10 ** 18

# skip (0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
itr = product([0, 1], repeat=10)
itr.__next__()
for bit in itr:
    cand = sum((P[i][sum((f*b for f, b in zip(F[i], bit)))] for i in range(N)))
    ret = max(ret, cand)

print(ret)

Submission status: Accepted

Solution code:
#coding: utf-8
from collections import deque

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

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

ret = None
for bit in range(1, 2**10):
    nWork = [0] * N
    for i in range(10):
        if (bit >> i) & 1:
            for shop in range(N):
                if F[shop][i] == 1:
                    nWork[shop] += 1

    cand = 0
    for i in range(N):
        cand += P[i][nWork[i]]
    if ret == None or cand > ret:
        ret = cand
print(ret)

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
A = [0, 1]
M = -10**18
Pr = list(product(A, repeat=10))
Pr.remove((0,0,0,0,0,0,0,0,0,0))
for I in Pr:
  s = 0
  for i in range(N):
    s += P[i][sum(i*f for i, f in zip(I, F[i]))]
  M = max(M, s)
print(M)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
F = np.array([list(map(int, input().split())) for i in range(N)])
P = np.array([list(map(int, input().split())) for i in range(N)])
ans = -10**18
for i in range(2**10):
    box = []
    for k in range(10):
        if ((i>>k)&1):
            box = [1]+ box
        else:
            box = [0]+ box
    if all(i == 0 for i in box):
        continue
    # box は開業する0~9の候補リスト
    # G は F(0か1の各店開業状況)
    G = np.sum(F*box, axis=1)
    a = 0
    for x,y in zip(G,P):
        a += y[x]
    ans = max(ans, a)
    
print(ans)

Submission status: Accepted

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

n = int(input())

shops = []
for _ in range(n):
    s = [int(i) for i in input().split()]
    shops.append(s)

profits = []
for _ in range(n):
    p = [int(i) for i in input().split()]
    profits.append(p)

ans = -1 * float('inf')
for i in range(1, 2 ** 10):
    revenue = 0
    for j in range(n):
        c = 0
        s = shops[j]
        for k in range(10):
            if s[k] and (i >> k) & 1:
                c += 1
        revenue += profits[j][c]
    ans = max(ans, revenue)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

f = [[] for _ in range(n)]
a = [[] for _ in range(n)]

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

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

ans = -float("inf")
for times in range(1, 1 << 10):
    profit = 0
    for i in range(n):
        cnt = 0
        for j in range(10):
            if times >> j & 1 and f[i][j]:
                cnt += 1
        profit += a[i][cnt]

    ans = max(ans, profit)

print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

ans = -INF
for i in range(1, 1 << 10):
    profit = 0
    for k in range(N):
        cnt = 0
        for j in range(10):
            if i & 1 << j > 0 and F[k][j] == 1:
                cnt += 1
        profit += P[k][cnt]
    ans = max(ans, profit)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
f=[]
for i in range(n):
    fn=[int(x) for x in input().rstrip().split()]
    f.append(fn)

p=[]
for i in range(n):
    pn=[int(x) for x in input().rstrip().split()]
    p.append(pn)

ans=-float('inf')
for i in range(1,2**10):
    now=0
    for s in range(n):
        cnt=0
        for j in range(10):
            if ((i>>j) & 1) and f[s][j]==1:
                cnt+=1
        now+=p[s][cnt]
    ans=max(ans,now)
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

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 ** 18
for i in range(1, 11):
    for pat in combinations(range(10), i):
        cnt = [0] * n
        for e in pat:
            for j in range(n):
                cnt[j] += f[j][e]

        score = 0
        for i, e in enumerate(cnt):
            score += p[i][e]

        ans = max(ans, score)

print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import product

input = sys.stdin.readline


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

    ans = -float("inf")
    for comb in product(range(2), repeat=10):
        if sum(comb) == 0:
            continue
        c = [0] * N
        for j, is_open in enumerate(comb):
            if is_open:
                for i in range(N):
                    c[i] += F[i][j]
        profit = sum(P[i][c[i]] for i in range(N))
        ans = max(ans, profit)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()


def main():
    n = int(input())
    F = [[] for _ in range(n)]
    for w in range(n):
        l = list(map(int, input().split()))
        for i in range(5):
            F[w].append(l[i * 2: i * 2 + 2])
    P = [list(map(int, input().split())) for _ in range(n)]

    ans = -10**10
    for case in range(1, 1 << 10):
        profit = 0
        for i in range(n):
            c = 0
            for t in range(10):
                if F[i][t // 2][t % 2] and case & (1 << t): c += 1
            profit += P[i][c]
        ans = max(ans, profit)
    print(ans)



if __name__ == "__main__":
    main()

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())))
ans = -10**9
for i in range(1, 1 << (10)):
    C = [0]*n
    for j in range(10):
        if i & 2**j:
            for k in range(n):
                if F[k][j]:
                    C[k] += 1
    current = 0
    for k in range(n):
        current += P[k][C[k]]
    ans = max(current, ans)
print (ans)

Submission status: Accepted

Solution code:
from math import inf

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

ans = -inf
for bit in range(1,1024):
    res = 0
    for j in range(n):
        c = 0
        for k in range(10):
            mask = 1 << k
            if f[j][k] and bit&mask:
                c+=1
        res += p[j][c]
    ans = max(ans, res)
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

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

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

ite = product(range(2),repeat=10)
ans = -1*(10**9)
for it in ite:
    pattern = list(it)
    if 1 not in pattern: continue
    each_cnt = [0]*n
    for i,v in enumerate(pattern):
        if v == 1:
            for j,f in enumerate(fl):
                if f[i] == 1:
                    each_cnt[j] += 1
    val = 0
    for i, c in enumerate(each_cnt):
        val += pl[i][c]
    ans = max(ans,val)

print(ans)

Submission status: Accepted

Solution code:
import sys
n = int(input())
F = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
P = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
ans = -pow(10,9)-7
for i in range(1,pow(2,10)):
    b = bin(i)[2:].zfill(10)
    t = 0
    for j in range(n):
        c = 0
        for k in range(10):
            if int(b[k]) and F[j][k]:
                c += 1
        t += P[j][c]
    ans = max(ans, t)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
F = [int("".join(input().split()),2) for n in range(N)]
P = [list(map(int,input().split())) for n in range(N)]
print(max(sum(p[bin(n&f).count("1")]for f,p in zip(F,P)) for n in range(1,1024)))

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 = []

for i in range(1,1024):
  p = 0
  for j in range(N):
    c = 0
    for k in range(10):
      if (i>>k&1) & F[j][k]:
        c+=1
    p+=P[j][c]
  ans+=[p]
    
print(max(ans))

Submission status: Accepted

Solution code:
from itertools import product
n=int(input())
fs=[list(map(int,input().split())) for _ in range(n)]
ps=[list(map(int,input().split())) for _ in range(n)]
ans=-float('inf')
for b in product((0,1),repeat=10):
    if sum(b)==0:
        continue
    v=0
    for f,p in zip(fs,ps):
        cnt=sum([a&b for a,b in zip(b,f)])
        v+=p[cnt]
    ans=max(ans,v)
print(ans)

Submission status: Accepted

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

ans=-float("inf")
for i in range(1,2**10):
    tmp=0
    joi_open=[0]*10
    for j in range(10):
        if (i>>j)&1:
            joi_open[j]=1
    for j in range(n):
        cnt=0
        for k in range(10):
            if open[j][k]==joi_open[k]==1:
                cnt+=1
        tmp+=point[j][cnt]
    ans=max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
def solve():
    import numpy as np
    n = int(input())
    oc = [list(map(int, input().split())) for _ in range(n)]
    prof = [list(map(int, input().split())) for _ in range(n)]

    oc = np.array(oc)
    prof = np.array(prof)

    inf = 10 ** 10
    ans = - inf

    for a in range(1, 1 << 10):
        res = np.zeros(n, dtype=np.int64)
        for b in range(10):
            if a >> b & 1:
                res += oc[:, b]
        tmp = 0
        for i, x in enumerate(res):
            tmp += prof[i, x]
        ans = max(ans, tmp)
    print(ans)


solve()

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    oc = [list(map(int, input().split())) for _ in range(n)]
    prof = [list(map(int, input().split())) for _ in range(n)]

    inf = 10 ** 16
    ans = - inf

    for a in range(1, 1 << 10):
        res = 0
        for i in range(n):
            cnt = 0
            for x in range(10):
                if a >> x & 1 and oc[i][x] == 1:
                    cnt += 1
            res += prof[i][cnt]
        ans = max(ans, res)
    print(ans)


solve()

Submission status: Accepted

Solution code:
def solve():
    import numpy as np
    n = int(input())
    oc = [[] for _ in range(n)]
    prof = [[] for _ in range(n)]

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

    oc = np.array(oc)
    prof = np.array(prof)

    ans = -9999999999

    for a in range(1, 1 << 10):
        res = np.zeros(n, dtype=np.int64)
        for b in range(10):
            if a >> b & 1:
                res += oc[:, b]
        #print(res)
        tmp = 0
        for i, x in enumerate(res):
            tmp += prof[i, x]
        #print(tmp)
        ans = max(ans, tmp)
    print(ans)


solve()

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    oc = [list(map(int, input().split())) for _ in range(n)]
    prof = [list(map(int, input().split())) for _ in range(n)]

    ans = -9999999999

    for a in range(1, 1 << 10):
        res = 0
        for i in range(n):
            cnt = 0
            for x in range(10):
                if (a >> x) % 2 == 1 and oc[i][x] == 1:
                    cnt += 1
            res += prof[i][cnt]
        ans = max(ans, res)
    print(ans)


solve()

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, 1024):
    fund = 0
    for i in range(n):
        cou = 0
        for x in range(10):
            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:
import numpy as np
N = int(input())

F = np.empty((N,10))
P = np.empty((N,11))
for i in range(N):
  Flist = np.array(list(map(int, input().split())), dtype = int)
  F[i] = Flist
for i in range(N):
  Plist = np.array(list(map(int, input().split())), dtype = int)
  P[i] = Plist
BenefitMax = 0

for i in range(1,1024):
  A = np.zeros(10)
  iForBin = i
  for j in range(10):
    if iForBin %2 == 1:
      A[j] = 1
    iForBin = iForBin // 2
  ADotF = np.tensordot(A,F,((0),(1)))
  Benefit = 0
  for j in range(N):
    Benefit += P[j,int(ADotF[j])]
  if i == 1:
    BenefitMax = Benefit
  else:
    if BenefitMax < Benefit:
      BenefitMax = Benefit

print(int(BenefitMax))

Submission status: Accepted

Solution code:
from itertools import product
N=int(input())

F=[]
P=[]

for n in range(N):
    F.append(list(map(int,input().split())))
    
for n in range(N):
    P.append(list(map(int,input().split())))

ans=-10**10
for p in product(range(2),repeat=10):
    if len(set(p))==1 and p[0]==0:
        continue
    p_ = 0
    for idx,f in enumerate(F):
        c=0
        for i in range(10):
            c += f[i]*p[i]
        p_ += P[idx][c]
        
    if ans < p_:
        ans=p_
        
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
 
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)])
 
ans = - (10 ** 11)
 
for n in range(1, 1024):
    bits = np.array(list(map(int, list('{:010b}'.format(n)))))
    dup = np.sum(F * bits, axis=1)
    ans = max(ans, np.sum(P[range(N), dup]))

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
data1 = [list(map(int,input().split())) for _ in range(n)]
data2 = [list(map(int,input().split())) for _ in range(n)]
ans = []
trans = -1
for i in range(2**10):
    S = [0]*n
    l = 0
    for j in range(10):
        for k in range(n):
            S[k] += data1[k][j]*((i>>j)&1)
    for j in range(n):
        l += data2[j][S[j]]
    ans.append(l)
    if not i:
        trans = l
ans.sort()
print(ans[-1] if ans[-1] != trans else ans[-2])

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 = -9999999999
for i in range(1, 2 ** 10):
    s = 0
    for j in range(N):
        cnt = 0
        for k in range(10):
            if i >> k & 1 and F[j][k] == 1:
                cnt += 1
        s += P[j][cnt]
    ans = max(ans, s)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
m=10
f=[list(map(int,input().split())) for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(n)]
ans=-10**18
for i in range(1,2**m):
  s=0
  for j in range(n):
    cnt=0
    for k in range(m):
      if (i>>k)&1 and f[j][k]:
        cnt+=1
    s+=p[j][cnt]
  ans=max(s,ans)
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)]

# bit全探索
inf = float("inf")
ans = -inf
for i in range(1, 2**10):
    op = []
    for j in range(10):
        if (i >> j) & 1:
            op.append(1)
        else:
            op.append(0)

    res = 0
    for k in range(N):
        temp = 0
        for l in range(10):
            if op[l] == 1 and F[k][l] == 1:
                temp += 1
        res += P[k][temp]
    ans = max(ans, res)

print(ans)

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,2**10):#joisinoお姉ちゃんが営業するしないの組み合わせ1024通り
  fund = 0
  for i in range(N):#店の数
    cou = 0
    for x in range(10):#営業タイミング（月~金それぞれ午前、午後）
      if (item >> x) % 2 == 1 and arr[i][x] == 1:#joisino姉の開店と店iの開店が一致
        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)]

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

print(res)

Submission status: Accepted

Solution code:
import sys
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')

INF = 10**9 + 7


def main():
    N = in_n()
    F = [in_nl() for _ in range(N)]
    P = [in_nl() for _ in range(N)]

    comb = list(itertools.product(range(2), repeat=10))[1:]

    ans = -INF
    for com in comb:
        r = 0
        for i in range(N):
            count = 0
            for j in range(10):
                if F[i][j] == com[j] == 1:
                    count += 1
            r += P[i][count]
        ans = max(ans, r)

    print(ans)


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**10)
for i in range(1,1024):
    bit=bin(i)[2:].zfill(10)
    a=0
    for j in range(n):
        b=0
        for k in range(10):
            if int(bit[k]) and f[j][k]:
                b+=1
        a+=p[j][b]
    ans=max(ans,a)
print(ans)

Submission status: Accepted

Solution code:
# ビット全探索
from itertools import product

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 product([True, False], repeat=10):
    if i.count(False) == 10:
        continue
    t = 0
    for j in range(N):
        t += P[j][sum(1 & F[j][k] for k in range(10) if i[k])]
    result = max(result, t)
print(result)

Submission status: Accepted

Solution code:
n = int(input())
F = [tuple(int(x) for x in input().split()) for _ in range(n)]
P = [tuple(int(x) for x in input().split()) for _ in range(n)]
ans = -10**18
for bit in range(1, 1<<10):
    A = [0] * n  # 被り数
    for i in range(10):
        if bit & (1<<i):  # 開店
            for j in range(n):
                if F[j][i] == 1:
                    A[j] += 1
    profit = 0
    for j in range(n):
        profit += P[j][A[j]]
    ans = max(ans, profit)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
F = []
ans = -float('inf')
for i in range(n):
    a = "".join(input().split())
    a = int(a, 2)
    F.append(a)
p = [list(map(int,input().split())) for i in range(n)]
for i in range(1,2**10):
    tmp = 0
    for j in range(n):
        cnt = bin(i&F[j]).count("1")
        tmp +=p[j][cnt]
    else:
        ans = max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
f = [lr() for i in range(n)]
p = [lr() for i in range(n)]
ans = -inf
for i in range(1,2**10):
    pre = 0
    num = [0 for k in range(n)]
    for j in range(10):
        if (i >> j) & 1:
            for k in range(n):
                num[k] += f[k][j]
    for j in range(n):
        pre += p[j][num[j]]
    ans = max(ans, pre)
print(ans)

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    F = []
    for _ in range(N):
        f = list(map(int,input().split()))
        F.append(f)
    
    P = []
    for _ in range(N):
        p = list(map(int,input().split()))
        P.append(p)
    
    ans = -float('inf')
    for i in range(1, 1 << 10):
        me = [0] * 10
        for j in range(10):
            if (i >> j) & 1:
                me[j] = 1

        c = []
        for j in range(N):
            cnt = 0
            for k in range(10):
                if F[j][k] == 1 and me[k] == 1:
                    cnt += 1
            
            c.append(cnt)
        
        now = 0
        for j in range(N):
            now += P[j][c[j]]
        
        ans = max(ans, now)
    
    print(ans)
    
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
fs = [None]*n
for i in range(n):
    l = list(map(int, input().split()))
    fs[i] = set([i for i in range(10) if l[i]])
p = [None]*n
for i in range(n):
    p[i] = list(map(int, input().split()))
ans = -float("inf")
for b in range(1<<10):
    if b==0:
        continue
    score = 0
    s = set()
    for i in range(10):
        if b>>i&1:
            s.add(i)
    for i in range(n):
        score += p[i][len(s&fs[i])]
    ans = max(ans, score)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
f = []
ans = -10**9

for i in range(n):
    a = input().split()
    f.append(a)

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

for i in range(1, 2**10):
    ref = 0
    i = str(bin(i))[2:].zfill(10)
    for j in range(n):
        cnt = 0
        for k in range(10):
            if i[k] == f[j][k] == "1":
                cnt += 1
        ref += p[j][cnt]
    else:
        ans = max(ans, ref)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
F = []
for i in range(N):
    A = list(map(int, input().split()))
    F.append(A[::-1])
 
P = []
for i in range(N):
    A = list(map(int, input().split()))
    P.append(A)
 
result = float("inf")*(-1)
for i in range(1, 2**10):
    ans = 0
    for l in range(N):
        c = 0
        for j in range(10):
            if ((i>>j) & 1):
                if F[l][j] == 1:
                    c += 1
        ans += P[l][c]
    result = max(ans, result)
print(result)

Submission status: Accepted

Solution code:
from itertools import product
def main():
    N = int(input())
    F = []
    for _ in range(N):
        f = list(map(int, input().split()))
        F.append(f)
    P = []
    for _ in range(N):
        p = list(map(int, input().split()))
        P.append(p)
    m = -10**21
    for i in product(range(2), repeat=10):
        if sum(i) == 0:
            continue
        r = 0
        for j in range(N):
            r += P[j][sum(ii&jj for ii, jj in zip(i, F[j]))]
        m = max(r, m)
    return m
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 = -float('inf')

for i in range(2**10):
    bag = []
    for j in range(10):
        if (i>>j)&1:
            bag += [j]

    tmp = 0
    is_cnt = False
    for n in range(N):
        f = F[n]
        cnt = 0
        for b in bag:
            if f[b] == 1:
                cnt += 1
        tmp += P[n][cnt]
        if cnt:
            is_cnt = True
    
    if is_cnt:
        ans = max(ans, tmp)

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)]
ans=-10**9
for i in list(itertools.product(range(2),repeat=10)):
  if sum(i)==0:
    continue
  bns=0
  for j in range(N):
    b=0
    for k in range(10):
      if i[k]*F[j][k]==1:
        b+=1
    bns+=P[j][b]
  ans=max(ans,bns)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
f = []
ans = -10**9

for i in range(n):
    a = "".join(input().split())
    a = int(a, 2)
    f.append(a)

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

for i in range(1, 2**10):
    ref = 0
    for j in range(n):
        cnt = bin(i&f[j]).count("1")
        ref += p[j][cnt]
    else:
        ans = max(ans, ref)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
f = []
ans = -10**9

for i in range(n):
    a = "".join(input().split())
    a = int(a, 2)
    f.append(a)

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

for i in range(1, 2**10):
    ref = 0
    for j in range(n):
        cnt = bin(i & f[j]).count("1")
        ref += p[j][cnt]
    else:
        ans = max(ans, ref)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
l = []
m = []
ans = -10**9

for i in range(n):
    f = "".join(input().split())
    f = int(f, 2)
    l.append(f)

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

for i in range(1, 2**10):
    ref = 0
    for j in range(n):
        cnt = bin(i & l[j]).count("1")
        ref += m[j][cnt]
    else:
        ans = max(ans, ref)

print(ans)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
F =[ list(input().split()) for i in range(N)]
P =[ list(input().split()) for i in range(N)]
set01 = list(itertools.product('01',repeat = 10))
counter = []
ans = -10**9
for s01 in set01:
    if s01 != ("0","0","0","0","0","0","0","0","0","0"):
        prof = 0
        for i in range(N):
            counter = 0
            for j in range(10):
                if s01[j] =="1" and F[i][j] == "1":
                    counter += 1
            prof += int(P[i][counter])
        ans = max(ans,prof)
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)]

res = -(1<<30)

for b in range(1,1<<10):
  cc = 0
  for i in range(N):
    c = 0
    for j in range(10):
      if (b>>j&1) & F[i][j]:
        c+=1
    cc += P[i][c]
  if res<cc:
    res = cc
    
print(res)

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):
        tnp = 0
        for k in range(10):
            if ((i>>k)&1):
                if (f[j][k]==1):
                    tnp += 1
        res += p[j][tnp]
    ans = max(ans,res)
print(ans)