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 _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]

ans = -10 ** 20
for i in range(1, 2 ** 10):
    cnt = [0] * n
    calc = 0
    for j in range(10):
        if i >> j & 1:
            for k in range(n):
                if f[k][j] == 1:
                    cnt[k] += 1
                
    for k in range(n):
        calc += p[k][cnt[k]] 
    
    ans = max(ans, calc)

print(ans)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    F = [int(input().replace(" ", ""), 2) for i in range(N)]
    P = [list(map(int, input().split(" "))) for i in range(N)]
    maxtotal = -1*float("inf")
    maxpattern = ""
    for bits in range(1, (1<<10)):
        total = 0
        for i in range(N):
            c = bin(bits & F[i]).count("1")
            total += P[i][c]
        if maxtotal < total:
            maxpattern = bits
            maxtotal = total
    print(maxtotal)




if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
#Forestの
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 ** 30
for i in range(1, 2 ** 10):
    cnt = [0] * n
    calc = 0
    #print(cnt)
    for j in range(10):
        if i >> j & 1:
            for k in range(n):
                if f[k][j] == 1:
                    cnt[k] += 1
    
                
    for k in range(n):
        calc += p[k][cnt[k]] 
    
    ans = max(ans, calc)

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)]
#利益
ans=-10**50
for z in product((0, 1), repeat=10):#bit全探索のくみあわせを勝手に作ってくれるので使うとよい
    profit_count=0  #利益の合計
    for i in range(n):
        work_count=0  #働く時間帯が同じ回数
        for j in range(10):  #個数を調べる
            if f[i][j]==1 and z[j]==1:  #f[i][j]==z[j]だと両方0の時もcountしちゃう
                work_count+=1
        profit_count+=p[i][work_count]
    if ans<profit_count:  #ans=max(ans,profit_count)だと000000000000の時確認できない
        if 1 in z:   #１日以上働いているかの確認
            ans=profit_count
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
A = {}
B = {}
N = int(input())

for n in range(1, N + 1):
    A[n] = input().split()

for n in range(1, N + 1):
    B[n] = [int(m) for m in input().split()]


ans = -10**10

for C in product(('1', '0'), repeat=10):
    if C != tuple('0' * 10):
        D = {v: 0 for v in range(1, N + 1)}
        E = 0
        for u in range(0, 10):
            for v in range(1, N + 1):
                if C[u] == A[v][u] == '1':
                    D[v] += 1

        for v in D:
            E += B[v][D[v]]

        if E > ans:
            ans = E

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 ** 18)
for op in range(1, 2 ** 10):
  overlaps = [0] * n
  for k,v in enumerate(f):
    overlap = 0
    for j in range(10):
      if ((op >> j) & 1) and v[j]:
        overlap += 1
    overlaps[k] = overlap
  tmp = 0
  for k,v in enumerate(overlaps):
    tmp += p[k][v]
  ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
sche=[0 for i in range(n)]
#ith store,jth day ,kth time >sche[i][2*(j-1)+(k-1)]
for h in range(n):
    sche[h]={i for i,v in enumerate(input().split()) if v=="1" }
profit=[list(map(int,input().split())) for i in range(n)]
ans=-float("INF")
for i in range(1,1024):
    op={j for j in range(10) if (i>>j)%2}
    pre=0
    for g in range(n):
        pre+=profit[g][len(op&sche[g])]
    ans=max(pre,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)]
ans = -1e100
for i in range(1,2**10):
    A = [0]*10
    profit = 0
    j = 0
    while i > 0:
        A[j] += i&1
        j += 1
        i = i >> 1
    for j in range(n):
        dup = 0
        for a,f in zip(A,F[j]):
            dup += a&f
        profit += P[j][dup]
    ans = max(ans,profit)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
shop = [] # 10
profit = [] # 11
for i in range(n):
    shop.append(list(map(int,input().split())))
for i in range(n):
    profit.append(list(map(int,input().split())))
cond = [bin(i)[2:].zfill(10) for i in range(1,2**10)]
ans = -int(1e15)
for i in range(len(cond)):
    pro_cnt = 0
    tar = cond[i]
    for j in range(n):
        tar_shop = shop[j]
        cnt = 0
        for k in range(10):
            if int(tar[k]) & tar_shop[k] == 1:
                cnt += 1
        pro_cnt += profit[j][cnt]
    ans = max(ans, pro_cnt)
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:10*n+1].reshape(n, 10)
p = I[10*n+1:].reshape(n, 11)

def main():
    combs = np.arange(1, 1 << 10)[:, None] >> np.arange(10) & 1
    res = (combs[:, None] & f).sum(axis=2)
    res = p[np.arange(n), res[:, None]].sum(axis=2)
    print(res.max())

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)]
print(max(sum(p[j][sum(i>>k&1 and f[j][k] for k in range(10))] for j in range(n)) for i in range(1,2**10)))

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,2**10):
    a = 0
    for j in range(n):
        a += p[j][sum(i>>k&1 and f[j][k] for k in range(10))]
    ans = max(ans,a)
print(ans)

Submission status: Accepted

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""
# 最大公約数 と 最小公倍数
"""def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def lcm(a,b):
  g = gcd(a,b)
  return (a * b) // g"""
# 二分探索
"""import bisect # 二分探索
print(A,bisect.bisect_left(A,4))
print(C,n - bisect.bisect_right(C,4))
print(sum(bisect.bisect_left(A,b) * (n-bisect.bisect_right(C,b)) for b in B))"""

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7

def main():
  n = int(input())
  F = [readInts() for _ in range(n)]
  P = [readInts() for _ in range(n)]
  
  max_score = -float('inf')
  
  for i in range(1, 2**10):
    op_num = [0] * n
    for j in range(10):
      if i & 1 << j:
        for n_i in range(n):
          op_num[n_i] += F[n_i][j]
    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)
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
from sys import stdin
import itertools

N = int(stdin.readline().rstrip())
F = []

for i in range(N):
    f = [int(x) for x in stdin.readline().rstrip().split()]
    F.append(f)
    
P = []
for i in range(N):
    p = [int(x) for x in stdin.readline().rstrip().split()]
    P.append(p)

ans = -10**9
for i in itertools.product([0,1],repeat=10):
    if sum(i) == 0:
        continue
    score = 0
    for ind,f in enumerate(F):
        num = sum([j*k for j,k in zip(i,f)])
        score += P[ind][num]
    ans = max(ans,score)
    
print(ans)

Submission status: Accepted

Solution code:
import itertools

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

it = itertools.product((0, 1), repeat=10)
next(it)

ans = -float('inf')
for t in it:
    p_sum = 0
    for i in range(N):
        c = sum(F[i][x] * t[x] for x in range(10))
        p_sum += P[i][c]
    ans = max(ans, p_sum)

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

Submission status: Accepted

Solution code:
n = int(input())
F = [[int(x) for x in input().split()] for i in range(n)]
P = [[int(x) for x in input().split()] for i in range(n)]
res = -10**12
for bit in range(1, 2 ** 10):
    cc = 0
    for i in range(n):
        cc += P[i][sum([(F[i][j]==1 and (1 & (bit >> j))==True) for j in range(10)])]
    res = max(res, cc)
print(res)

Submission status: Accepted

Solution code:
n = int(input())
list_F = [ list(map(int,input().split(" "))) for i in range(n)]
list_P = [ list(map(int,input().split(" "))) for i in range(n)]
ans = (-1)*pow(10, 9)
a = 0
for i in range(1, 2**10):
    value = 0
    for k in range(n):
        l = list_F[k]
        cnt = 0
        for j in range(10):
            if ((i >> j) & 1):
                if l[j] == 1:
                    cnt += 1
        value += list_P[k][cnt]
    ans = max(ans, value)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
 
F = []
 
for _ in range(N):
    f = list(input().strip().split())
    F.append(int("".join(f), 2))

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

ans = -10**10-7

for i in range(1,2**10):
    candi = 0
    for j in range(N):
        tmp = i & F[j]
        p = format(tmp, 'b').count("1")
        candi += P[j][p]
    ans = max(ans,candi) 
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

F = []

for _ in range(N):
    f = list(input().strip().split())
    F.append(int("".join(f), 2))


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

ans = -float('inf')

for i in range(1, 2**10):
    candi = 0
    for n in range(N):
        tmp = i & F[n]
        p = format(tmp, 'b').count("1")
        candi += P[n][p]
    if candi == 0:
        foo = 1
    ans = max(ans, candi)

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

ans = -(int(1e9) + 7)
#print(ans)
for i in range(2 ** 10):
    d = [False] * 10
    for j in range(10):
        if i >> j & 1:
            d[j] = True
    if not True in d:
        continue

    val = 0
    for j in range(n):
        cnt = 0
        for k in range(10):
            if d[k] == True and f[j][k] == 1:
                cnt += 1
        val += p[j][cnt]
        #print(ans)
    ans = max(ans,val)
print(ans)

Submission status: Accepted

Solution code:
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
f = []
p = []
for i in range(n):
    f.append(inl())
for i in range(n):
    p.append(inl())
mx = -BIG
for t in range(1,2**10):
    s = [(t>>i)%2 for i in range(10)]
    sm = 0
    for i in range(n):
        x = sum([s[j]*f[i][j] for j in range(10)])
        sm += p[i][x]
    mx = max(mx,sm)
print(mx)

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**18

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
fll = []
pll = []

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

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

ans = -float("inf")
from itertools import product
for bits in product([0, 1], repeat=10):
    if sum(bits) == 0:
        continue
    tmp = 0
    for fl, pl in zip(fll, pll):
        count = 0
        for f, bit in zip(fl, bits):
            if f and bit:
                count += 1
        tmp += pl[count]
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc080/tasks/abc080_c
# 15:36-16:15 done

from copy import deepcopy


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

    # max_benefit = -(10**10)
    n_overlaps_list = []

    def rec(time_i, counts, flag):
        # print(counts)
        # exit()
        # 終章条件
        if time_i == 10:
            if not flag:
                # print(counts)
                n_overlaps_list.append(counts)
            return None

        counts_1 = deepcopy(counts)
        counts_2 = deepcopy(counts)

        for i in range(len(counts)):
            if F[i][time_i] == 1:
                counts_2[i] += 1

        rec(time_i+1, counts_1, flag and True)  # 開かない
        rec(time_i+1, counts_2, False)  # 開く

    rec(0, [0] * N, True)
    # print(n_overlaps_list)

    ans = -(10**10)
    tmp = None
    for n_overlaps in n_overlaps_list:
        candidate = 0
        for i in range(N):
            candidate += P[i][n_overlaps[i]]
        if candidate > ans:
            ans = candidate
            tmp = n_overlaps
    # print(tmp)
    
    return ans


print(main())

Submission status: Accepted

Solution code:
N = int(input())

F = []
for _ in range(N):
    tmp = list(map(int, input().split()))
    v = 0
    for i in range(5 * 2):
        v += tmp[i] << i
    F.append(v)

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

ans = -1 * (10**12)
for bit in range(1, 1 << (5 * 2)):
    v = 0
    for i in range(len(F)):
        f = F[i]
        product = bit & f
        cnt = 0
        for j in range(5 * 2):
            if product & (1 << j):
                cnt += 1
        v += P[i][cnt]
    ans = max(ans, v)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
f = [0]*n
for i in range(n):
  f[i] = [int(x) for x in input().split()]

p = [0]*n
for i in range(n):
  p[i] = [int(x) for x in input().split()]

ans = -10**9-7

for i in range(2**10):
  o = [0]*10
  for j in range(10):
    if (i >> j) & 1:
      o[j] = 1
  if not any(o):
    continue
  sub = 0
  for k in range(n):
    key = 0
    for j in range(10):
      if o[j] and f[k][j]:
        key += 1
    sub += p[k][key]
  if sub > ans:
    ans = sub

print(ans)

Submission status: Accepted

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


try:
    from typing import List
except ImportError:
    pass


def solve(N: int, F: "List[List[int]]", P: "List[List[int]]"):
    print(max(
        sum(
            Pi[sum(ptnj * Fij for ptnj, Fij in zip(ptn, Fi))]
            for Fi, Pi in zip(F, P)
        )
        for ptn in product((0, 1), repeat=10)
        if sum(ptn) != 0
    ))


def main():
    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)
    ]
    solve(N, F, P)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

cnts = [0] * 10
for F in Fs:
    for i,f in enumerate(F):
        cnts[i] += f

ans = -10**10
for i in range(1,2**10):
    bs = list(bin(i)[2:].zfill(10))
    cnt_all = 0
    for fs,ps in zip(Fs, Ps):
        cnt = 0
        for i in range(10):
            if int(bs[i]) * int(fs[i]) == 1:
                cnt += 1
        cnt_all += ps[cnt]
    ans = max(cnt_all,ans)
    # print(bs,cnt)
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())))
#print(N)
#print(list(map(bin, F)))
#print(P)

profit_list=[]
for i in range(1, 2 ** 10):
    profit=0
    for k in range(N):
        kaburi = i & F[k]
        #print(bin(i), bin(F[k]), bin(kaburi))
        kaburi_count=0
        for j in range(10):
            if ((kaburi >> j) & 1):
                kaburi_count+=1
        profit+=P[k][kaburi_count]
    profit_list.append(profit)
#print(profit_list)
print(max(profit_list))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from itertools import combinations

def readlines(n):
    for _ in range(n):
        yield list(map(int,input().split()))

def bene(me, f, p):
    a = len([0 for m in me if f[m] == 1])
    return p[a]

def main():
    n = int(input())
    F = list(readlines(n))
    P = list(readlines(n))

    for i in range(1, 11):
        for comb in combinations(range(10), i):
            yield sum(bene(comb, f, p) for f, p in zip(F,P))

    
print(max(main()))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from itertools import combinations

def readlines(n):
    for _ in range(n):
        yield list(map(int,input().split()))

def bene(me, f, p):
    a = sum(1 if f[m] == 1 else 0 for m in me)
    return p[a]

def main():
    n = int(input())
    F = list(readlines(n))
    P = list(readlines(n))

    for i in range(1, 11):
        for comb in combinations(range(10), i):
            yield sum(bene(comb, f, p) for f, p in zip(F,P))

    
print(max(main()))

Submission status: Accepted

Solution code:
N=int(input())
F=[int('0b'+''.join(list(input().split(' '))),0) for i in range(N)]
P=[list(map(int,input().split(' '))) for i in range(N)]
ans = -float('inf')
for i in range(1,1024):
    tmp = 0
    for j,k in zip(P,F):
        tmp += j[str(bin(i&k)).count('1')]
    ans = max(tmp,ans)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
F = []
for i in range(n):
  f = list(map(int,input().split()))
  shop = []
  for j in range(5):
    shop.append([f[2*j],f[2*j+1]])
  F.append(shop)
P = [list(map(int,input().split())) for _ in range(n)]

import numpy as np
ans = -float('inf')
for i in range(1,2**10):
  index =format(i,'b').zfill(10)
  open_j = [int(j) for j in index]
  open_j = np.array(open_j).reshape(5,2)
  score = 0
  for j in range(n):
    count = 0
    for k in range(5):
      for l in range(2):
        if F[j][k][l] and open_j[k][l]:
          count += 1
    score += P[j][count]
  ans = max(ans,score)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
opened = [int('0b' + input().replace(' ', ''), 2) for i in range(n)]
prise = [list(map(int, input().split())) for i in range(n)]

ans = -float('INF')
for i in range(1,int('10000000000', 2)):
    cnt = [0 for i in range(n)]
    for j in range(10):
        if 1<<j & i == 0:
            continue
        for k in range(n):
            if 1<<j & opened[k]:
                cnt[k] += 1
    tmp = sum([prise[k][cnt[k]] for k in range(n)])
    if tmp > ans:
        # print(bin(i), tmp, [prise[k][cnt[k]] for k in range(n)], cnt)
        ans = tmp
print(ans)
# print(bin(2^10-1))
# [print(bin(i)) for i in opened]

Submission status: Accepted

Solution code:
n=int(input())
S=[int(input().replace(' ',''),2) for _ in range(n)]
C=[list(map(int,input().split())) for _ in range(n)]
A=[]
for i in range(1,2**10):
    ans=0
    for j in range(n):
        cnt=bin(S[j]&i).count('1')
        ans+=C[j][cnt]
    A.append(ans)
print(max(A))

Submission status: Accepted

Solution code:
n=int(input())
S=[list(map(str,input().split())) for _ in range(n)]
C=[list(map(int,input().split())) for _ in range(n)]
A=[]
for i in range(1,2**10):
    ans=0
    X=format(i,'b').zfill(10)
    for j in range(n):
        cnt=0
        for k in range(10):
            if S[j][k]=='1' and X[k]=='1':
                cnt+=1
        ans+=C[j][cnt]
    A.append(ans)
print(max(A))

Submission status: Accepted

Solution code:
n=int(input())
f=[ list(map(int,input().split())) for _ in range(n)]
#print(n)
p=[ list(map(int,input().split())) for _ in range(n)]
#print(f)
#print(p)
ans=-float('inf')
for mask in range(1,1<<10):
    su=0
    for i in range(n):
        cnt=0
        for j in range(10):
            if (mask>>j&1) and f[i][j]==1:
                cnt+=1
 #       print(i,cnt)
  #      print(len(p),len(p[0]))
        su+=p[i][cnt]
    ans=max(ans,su)
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)]

MaxValu = -2147483646
d = 2 ** 10
for i in range(1, d):
  tmp = i
  L = [0 for _ in range(10)]
  for j in range(10):
    L[j] = tmp % 2
    tmp //= 2
  val = 0
  for j in range(N):
    tmp2 = 0
    for m in range(10):
      tmp2 += F[j][m] * L[m]
    val += P[j][tmp2]
  if val > MaxValu:
    MaxValu = val
print(MaxValu)

Submission status: Accepted

Solution code:
n=int(input())
F=[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):
    cnt=0
    num=format(i,"b").zfill(10)
    for j,k in enumerate(F):
        cnt +=P[j][len([v for v in range(10) if k[v]==num[v]=="1"])]
    ans=max(ans,cnt)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
F=[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):
    cnt=0
    num=format(i,"b").zfill(10)
    for j,k in enumerate(F):
        cnt +=P[j][len([True for m in range(10) if k[m]==num[m]=="1"])]
    ans=max(ans,cnt)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

frr = []

for i in range(n):
    frr.append([int(s) for s in input().split(" ")])

prr = []

for i in range(n):
    prr.append([int(s) for s in input().split(" ")])

# n = 2
#
# frr = [
#     [1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
#     [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]
# ]
#
# prr = [
#     [0, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1],
#     [0, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1]
# ]


res = []
for i in range(1,2 ** 10):
    count = [0 for s in range(n)]

    mask = []
    for j in range(10):
        m =  i >> j & 1
        mask.append(m)
        if m == 1:
            for k in range(n):
                if frr[k][j] == 1:
                    count[k] = count[k] + 1

    mm = []
    for index,c in enumerate(count):
        mm.append(prr[index][c])

    res.append(sum(mm))

print(max(res))

Submission status: Accepted

Solution code:
n=int(input())
f=[[0 for i in range(10)] for j in range(n)]
for i in range(n):
  x=list(map(int,input().split()))
  f[i]=x[:]

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

val=[0 for _ in range(1023)]
#ans=0
zr=[0 for _ in range(n)]
for i in range(1,1024):  #bit
  mx=0
  x=i-1
  opn=zr[:]
  #print(bin(i))
  for j in range(10):  #時間帯
    k=i%2
    i=i//2
    if k==1:
      for l in range(n):  #店ごとに営業時間がかぶってるか
        opn[l]+=f[l][j]
  for l in range(n):
    mx+=p[l][opn[l]]
  val[x]=mx
  #print(*opn)




#print(f)
#print(p)
print(max(val))

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, 1 << 10):
    bit = i
    profit = 0
    for j in range(N):
        cnt = sum(F[j][k] & (bit >> k) for k in range(10))
        profit += P[j][cnt]
    ans = max(ans, profit)

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, 1 << 10):
    bit = [0] * 10
    for d in range(10):
        bit[d] = 1 if (i >> d) & 1 else 0
    profit = 0
    for j in range(N):
        cnt = sum(F[j][k] & bit[k] for k in range(10))
        profit += P[j][cnt]
    ans = max(ans, profit)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
max_num = -10**12
stores = {}

for i in range(n):
    stores[i] =[int('0b'+''.join(input().split()), 2)]
for i in range(n):
    stores[i].append(list(map(int, input().split())))
for i in range(1, 1024):
    total_sum = 0
    for j in range(n):
        common_open_time = bin(stores[j][0] & i).count('1')
        total_sum += stores[j][1][common_open_time]
    max_num = max(total_sum, max_num)
print(max_num)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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

    result = -10**10
    for i in range(1, 1 << 10):
        count = [0 for _ in range(N)]
        for j in range(10):
            for k in range(N):
                if (i >> j) & 1 == 1 and F[k][10 - j - 1] == 1:
                    count[k] += 1
        total = 0
        for k in range(N):
            total += P[k][count[k]]
        result = max(result, total)
    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
I=input;R=range;n=int(I())
lf=[int(I()[::2],2) for _ in R(n)]
lp=[list(map(int,I().split())) for _ in R(n)]
print(max(sum(p[bin(i&f).count('1')] for f,p in zip(lf,lp)) for i in R(1,1024)))

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
F = np.array([])
for i in range(n):
  F = np.append(F,np.array(list(map(int,input().split()))))
F = F.reshape([n,10])
p = [list(map(int,input().split())) for _ in range(n)]

ans = -10**9
for i in range(1,2**10):
  s = 0
  J = np.array([])
  for j in range(10):
    J = np.append(J,(i >> j) & 1)
  s = 0
  for j in range(n):
    s += p[j][int(np.dot(F[j],J))]
  ans = max(ans,s)
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)]
data = list(itertools.product(range(2), repeat = 10))[1:]
ans = -10**9
for d in data:
    a = 0
    for i in range(n):
        c = 0
        for j in range(10):
            if f[i][j] and d[j]: c+=1
        a+=p[i][c]
    ans = max(ans,a)
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**9
def bfs(x):
    if len(x) == 10:
        if 1 in x:
            global ans
            a = 0
            for i in range(n):
                f,p = F[i],P[i]
                c = 0
                for j in range(10):
                    if x[j] == f[j] == 1: c+=1
                a+=p[c]
            ans = max(ans,a)
    else:
        bfs(x + [0])
        bfs(x + [1])
bfs([])
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())))

ans = -10**10

for i in range(1,2**10):
    l = []
    ans1 = 0
    for j in range(10):
        if (i>>j) & 1:
            l.append(1)
        else:
            l.append(0)
    for k in range(n):
        count = 0
        for m in range(10):
            if l[m] == 1 and F[k][m] == 1:
                count += 1
        ans1 += P[k][count]
    ans = max(ans,ans1)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
F=[[0]*10 for i in range(n)]
for i in range(n):
  F[i]=list(map(int,input().split()))
P=[[0]*11 for i in range(n)]
for i in range(n):
  P[i]=list(map(int,input().split()))
ans=-10**10
for i in range(1,1024):
  s=format(i,"12b")
  A=[]
  for j in range(10):
    if s[-1-j]=="1":
      A.append(j)
  p=0
  for j in range(n):
    c=sum(F[j][A[k]] for k in range(len(A)))
    p=p+P[j][c]
  if p>ans:
    ans=p
print(ans)