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:
def count_set_bits(n):
    count = 0
    while n:
        count += n & 1
        n >>= 1
    return count


N = int(input())
F = [int("".join(input().split()), 2) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -float("inf")
for i in range(1, 1 << 10):
    tmp = 0
    for j in range(N):
        tmp += P[j][count_set_bits(i & F[j])]
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
F = [l() for _ in range(N)]
P = [l() for _ in range(N)]
ans = INF*-1
for bit in range(1,1<<10):
    nans = 0
    B = [(bit>>i)&1 for i in range(10)]
    for i in range(N):
        cnt = 0
        for j in range(10):
            if B[j] == 1 and F[i][j] == 1:
                cnt += 1
        nans += P[i][cnt]
    ans = max(ans,nans)
print(ans)

Submission status: Accepted

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

#print(F, P)
#print(4 >> 1)
ans = - 10 ** 10
#print(ans)
for i in range(1, 2 ** 10):#bit全探索 #0は空いてる時間帯がないのでカット
  open_n = [0] * N
  profit = 0
  for j in range(10):#10240通り
    if ((i >> j) & 1):#jの時間帯に空いてる
      for k in range(N):#100
        if F[k][j] == 1:
          open_n[k] += 1
  for l in range(N):
    profit += P[l][open_n[l]]
  if ans < profit:
    ans = profit
          
print(ans)

Submission status: Accepted

Solution code:
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)]
    ans = -(10**15)
    for i in range(2**10):
        tmp = []
        for j in range(10):
            if ((i >> j) & 1):
                tmp.append(j)
        if not tmp:
            continue
        score = 0
        for k in range(N):
            cnt = 0
            for l in range(10):
                if F[k][l] == 1 and l in tmp:
                    cnt += 1
            score += P[k][cnt]

        ans = max(ans, score)

    print(ans)
if __name__ == "__main__":
    main()

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:
n=int(input())
f=[]
for i in range(n):
    tmp=0
    op=list(map(int,input().split()))
    for j in range(10):
        tmp+=op[j]<<j
    f.append(tmp)

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

ans=-10**12
for i in range(1, 1<<10):
    tmp=0
    for j in range(n):
        consist=f[j]&i
        cnt=0
        for k in range(10):
            if (consist>>k)%2:
                cnt+=1
        tmp+=p[j][cnt]
    ans=max(ans,tmp)
print(ans)

Submission status: Accepted

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

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

ans=-10**12
for i in range(1, 1<<10):
    tmp=0
    for j in range(n):
        consist=list(bin(f[j]&i)[2:])
        cnt=0
        for k in consist:
            if k=='1':
                cnt+=1
        tmp+=p[j][cnt]
    ans=max(ans,tmp)
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:
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):
    score = 0
    jonson = [0 for _ in range(10)]

    #jonsonがお店を開く時間を決める
    for j in range(10):
        if ((i >> j)&1):
            jonson[j] = 1
    #他のお店とオープンがかぶっている時間を調べる
    for k in range(N):
        cnt = 0
        for l in range(10):
            if F[k][l] == jonson[l] == 1:
                cnt += 1
        score += P[k][cnt]

    ans = max(score, ans)

print(ans)

Submission status: Accepted

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

ci = 0
c = []
P_max = -1000000000
for i in range(2):
    for j in range(2):
        for k in range(2):
            for l in range(2):
                for m in range(2):
                    for n in range(2):
                        for o in range(2):
                            for p in range(2):
                                for q in range(2):
                                    for r in range(2):
                                        if i==0 and j==0 and k==0 and l==0 and m==0 and n==0 and o==0 and p==0 and q==0:
                                            r = 1
                                        P_sample = 0
                                        for s in range(N):
                                            ci = F[s][0]*i + F[s][1]*j + F[s][2]*k + F[s][3]*l + F[s][4]*m + F[s][5]*n + F[s][6]*o + F[s][7]*p + F[s][8]*q + F[s][9]*r
                                            P_sample += P[s][ci]
                                        P_max = max(P_max, P_sample)

print(P_max)

Submission status: Accepted

Solution code:
n = int(input())
op = []
for _ in range(n):
    l = list(map(int, input().split()))
    op.append(l)
score = []
for _ in range(n):
    l = list(map(int, input().split()))
    score.append(l)
final = -999999999999999999999999


for pat in range(1,2**10):
    openNum = [0] * n
    for i in range(10):
        if ((pat >> i) & 1) == 1:
            for j in range(n):
                if op[j][i] == 1:
                    openNum[j] += 1
    res = 0
    for i in range(n):
        res += score[i][openNum[i]]
    final = max(final, res)
print(final)

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:
def popcnt(n):
    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c >> 4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c >> 8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c >> 16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c >> 32) & 0x00000000ffffffff)
    return c


n = int(input())
f = [sum([(1 << (9 - x)) * y for x, y in enumerate(list(map(int, input().split())))]) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]

ans = -1 << 60
for i in range(1, 1024):
    tmp = 0
    for x, y in zip(f, p):
        tmp += y[popcnt(i & x)]
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
F = [[*map(int, input().split())] for _ in range(n)]
P = [[*map(int, input().split())] for _ in range(n)]
ans = -10000000*100
for i in range(1, 1<<10): # my shop open pattern 10bit, i:[0~1,1~1]
    s = 0
    for j in range(n): # the other shop
        cj = 0
        for k in range(10):
            if i>>k & 1 and F[j][k]: cj += 1
        s += P[j][cj]
    ans = max(ans ,s)
print(ans)

Submission status: Accepted

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

def c(i, open_pattern):
    ret = 0
    for j in range(10):
        if open_pattern>>j & 1: #open my shop
            if F[i][j]: ret += 1 # open your shop
    return ret

ans = -10000000*100
for i in range(1, 1<<10): # open pattern 10bit, i:[0~1,1~1]
    s = 0
    for j in range(n): # your shop
        cj = c(j, i)
        s += P[j][cj]
    ans = max(ans ,s)
print(ans)

Submission status: Accepted

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

def c(i, open_patern):
    ret = 0
    for j in range(10):
        if open_patern>>j & 1: #open my shop
            if F[i][j]: ret += 1 # open your shop
    return ret

ans = -10000000*100
for i in range(1, 1<<10): # open pattern 10bit, i:[0~1,1~1]
    s = 0
    for j in range(n): # your shop
        cj = c(j, i)
        s += P[j][cj]
    ans = max(ans ,s)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
F = []
# for _ in range(n):
#     f = list(map(int, input().split()))
#     # print(f)
#     F.append([\
#         [f[0],f[1]],\
#         [f[2],f[3]],\
#         [f[4],f[5]],\
#         [f[6],f[7]],\
#         [f[8],f[9]]\
#     ])

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

# print(*F,sep='\n')

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

# print(*P,sep='\n')

def c(i, open_my_shop):
    ret = 0
    for j in range(10):
        if open_my_shop>>j & 1: #open my shop
            if F[i][j]: # open your shop
                ret += 1
    return ret

ans = -10*10000000*10
# for i in range(1, 1<<10): # [0~1,1~1] 10bit
#     s = 0
#     for j in range(10): # open time zone
#         if i>>j & 1: # my shop (j+1) open
#             for k in range(n): # your shop
#                 ck = c(k, i)
#                 s += P[k][ck]
#     ans = max(ans ,s)

for i in range(1, 1<<10): # [0~1,1~1] 10bit
    s = 0
    for j in range(n): # your shop
        cj = c(j, i)
        s += P[j][cj]
    ans = max(ans ,s)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
f=[0]*n
p=[0]*n
INF=10**9
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=-INF
for i in range(1,1<<10):
    cnt=0
    l=[0]*n
    for j in range(10):
        if (i>>j)%2==1:
            for h in range(n):
                if f[h][j]==1:
                    l[h]+=1
    x=0
    for i in range(n):
        x+=p[i][l[i]]
    ans=max(x,ans)
print(ans)

Submission status: Accepted

Solution code:
def solve(bit):
    ret = 0
    for i in range(n):
        cnt = 0
        for j in range(10):
            if L[i][j] == bit[j] == 1:
                cnt += 1
        ret += p[i][cnt]
    return ret

n = int(input())
L = [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 << 10):
    bit = [0] * 10
    for j in range(10):
        if i >> j & 1:
            bit[j] = 1
    if 1 in bit:
        ans = max(ans, solve(bit))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
f_list = [int("".join(input().split()), 2) for _ in range(n)]
p_list = [[int(x) for x in input().split()] for _ in range(n)]
ans = -(10 ** 10)
for i in range(1, 2 ** 10):
    temp = 0
    for j in range(n):
        temp += p_list[j][bin(i & f_list[j]).count("1")]
    if temp > ans:
        ans = temp
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())))
maxp=-10**11
for i in range(1,2**10):
  prof=0
  s='{0:b}'.format(i)
  S=[]
  for i in range(len(s)):
    S.append(s[i])
  S.reverse()
  for i in range(10-len(s)):
    S.append('0')
  S.reverse()
  for j in range(n):
    count=0
    for k in range(10):
      count+=int(S[k])*F[j][k]
    prof+=P[j][count]
  maxp=max(maxp,prof)
print(maxp)

Submission status: Accepted

Solution code:
# 曜日と時間帯の組み合わせを1111111111の10ビットで全探索

import sys
readline = sys.stdin.readline

N = int(readline())
F = [None] * N
for i in range(N):
  F[i] = int(readline().rstrip().replace(" ",""),2)
    
P = [None] * N
for i in range(N):
  P[i] = list(map(int,readline().split()))
  
ans = -(10 ** 10)
for i in range(1, 2 ** 10):
  # joisinoが営業する時間帯の文字列11011101
  # 各店について、店jとANDを取って、1ビットの数を数えるとCが分かる
  point = 0
  for j in range(N):
    # 店j
    debug = False
    c = bin(i & F[j])[2:].count("1")
    point += P[j][c]
  if ans < point:
    ans = point
  
print(ans)

Submission status: Accepted

Solution code:
N,*f = map(int, open(0).read().split())
F = [f[i*10:i*10+10] for i in range(N)]
P = [f[N*10+i*11:N*10+i*11+11] for i in range(N)]
ans = -1 * pow(10,10)
opened = [0] * 10
for i in range(1,2**10):
    temp = 0
    for j in range(10):
        if i >> j & 1:
            opened[j] = 1
        else:
            opened[j] = 0
    for j in range(N):
        c = sum(opened[k]*F[j][k] for k in range(10))
        temp += P[j][c]
    ans = max(ans,temp)
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 ** 30)
for p in product(range(2), repeat=10):
    if sum(p) == 0: continue
    tmp = 0
    for i in range(N):
        # お店ごとにかぶっている日数を数える
        cnt = 0
        for j in range(10):
            if p[j] and F[i][j]:
                cnt += 1
        tmp += P[i][cnt]
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
from operator import mul
def main():
    n = int(input())
    f = [tuple(map(int, input().split())) for _ in range(n)]
    p = [tuple(map(int, input().split())) for _ in range(n)]

    patterns = tuple(product([0,1], repeat=10))
    results = []
    for pate in patterns:
        if sum(pate) == 0:
            continue
        r = 0
        for i1, fe in enumerate(f):
            r += p[i1][sum(tuple(map(mul, pate, fe)))]
        results.append(r)
    print(max(results))
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
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())))

cand = []
for i in range(1, 2 ** 10):
  cnt = [0] * n
  for j in range(10):
    if i & (1 << j):
      for k in range(n):
        if f[k][j]:
          cnt[k] += 1
  v = 0
  for k in range(n):
    v += p[k][cnt[k]]
  cand.append(v)
    
print(max(cand))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
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())))

cand = []
for i in range(1, 2 ** 10):
  cnt = [0] * n
  for j in range(10):
    if i & (1 << j):
      for k in range(n):
        if f[k][j]:
          cnt[k] += 1
  v = 0
  for k in range(n):
    v += p[k][cnt[k]]
  cand.append(v)
    
print(max(cand))

Submission status: Accepted

Solution code:
N = int(input())
F = []
P = []
for i in range(N):
    F += [list(map(int, input().split()))]
for i in range(N):
    P += [list(map(int, input().split()))]
ans = float('-inf')

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

Submission status: Accepted

Solution code:
N = int(input())
F = []
P = []
for i in range(N):
    F += [list(map(int, input().split()))]
for i in range(N):
    P += [list(map(int, input().split()))]
ans = float('-inf')

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

Submission status: Accepted

Solution code:
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)]
    ans = -float('inf')
    for i in range(1, 1 << 10):
        A = [0] * 10
        for j in range(10):
            if i >> j & 1:
                A[j] = 1
        C = [0] * n
        for k in range(n):
            c = 0
            for a, f in zip(A, F[k]):
                if a == f == 1:
                    c += 1
            C[k] = c
        ans = max(ans, sum([P[i][c] for i, c in enumerate(C)]))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools

n=int(input())

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

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

lis=[]
for i in list(itertools.product([0,1],repeat=10))[1:]:
    lisi=0
    for j in range(n):
        sj=0
        for k in range(10):
            sj+=i[k]*f[j][k]
        lisi+=p[j][sj]
    lis.append(lisi)

print(max(lis))

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):
    isOpen = []
    for j in range(10):
        if i & (1<<j):
            isOpen.append(1)
        else:
            isOpen.append(0)
    res = 0
    for j in range(n):
        cnt = 0
        for k in range(10):
            if isOpen[k] and f[j][k]:
                cnt += 1
        res += p[j][cnt]
    ans = max(ans, res)

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 bit in range(1, 1 << 10):
    tmp = 0
    for i in range(n):
        cnt = 0
        for j in range(10):
            if bit & 1 << j and f[i][j]:
                cnt += 1
        tmp += p[i][cnt]
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
X = open(0).readlines()
n = int(X[0])
F = []
for x in X[1:n+1]:
    F.append(list(map(int, x.split())))
P = []
for x in X[n+1:]:
    P.append(list(map(int, x.split())))

ans = -10**10
for i in range(1, 2**10):
    A = [(i >> j) & 1 for j in range(10)]
    s = 0
    for j in range(n):
        c = sum(p and a for p, a in zip(F[j], A))
        s += P[j][c]
    if ans < s:
        ans = s
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
c = [list(map(int, input().split())) for i in range(n)]
p = [list(map(int, input().split())) for i in range(n)]
ans2 = -10**10
for i in range(1, 2**10):
  ans = 0
  count = [0]*n
  for j in range(10):
     if ((i >> j) & 1):
        for k in range(n):
          if c[k][j] == 1:
            count[k] += 1
  for l in range(n):
    ans += p[l][count[l]]
  if ans> ans2:
    ans2 =ans
print(ans2)

Submission status: Accepted

Solution code:
import math

n=int(input())
f=list()
p=list()
ans=-10**10
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,1<<10):
    shop=list()
    cnt=[0]*n
    tmp=0
    for j in range(10):
        if i>>j&1:
            shop.append(j)
    for s in range(n):
        for k in shop:
            if(f[s][k]==1):
                cnt[s]+=1
        tmp+=p[s][cnt[s]]
    ans=max(ans,tmp)
print(ans)

Submission status: Accepted

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

ans = -float('inf')
for bit in range(1, 2 ** 10):
    # 1店舗ずつを処理
    score = 0
    for i in range(len(f)):
        # 曜日・時刻ごとのスコアを計算
        cnt = 0
        for j in range(10):
            # ある店舗のi番目の時刻と、bitが合致するかチェック
            if f[i][j] & (bit >> j):
                cnt += 1
        score += p[i][cnt]
    ans = max(score, ans)
print(ans)

Submission status: Accepted

Solution code:
MAX_TIME = 10
n = int(input().rstrip())
#２進法を
P = [sum(int(i) << MAX_TIME-k-1 for k, i in enumerate(input().rstrip().split())) for j in range(n)]
S = [list(map(int, input().rstrip().split())) for i in range(n)]
#予め2進数をカウントしておく
    # 予めビットをカウントしておく
pattern = [sum(i >> j & 1 for j in range(MAX_TIME)) for i in range(2 ** MAX_TIME)]
result = -float('inf')


for i in range(1, 2**MAX_TIME):
    temp = 0
    for l, j in zip(P, S):
        temp += j[pattern[l & i]]
    result = max(result, temp)
print(result)

Submission status: Accepted

Solution code:
import itertools
mylist = [0, 1]
n = int(input().rstrip())

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

maxnum = - float('inf')
for i in itertools.product(mylist, repeat = 10):
    if sum(i) == 0:
        continue
    sell = 0
    for j, k in zip(mise, mine):
        temp = 0
        for l in range(10):
            if j[l] == i[l] and j[l] == 1:
                temp += 1
        sell += k[temp]
    maxnum = max(maxnum, sell)
print(maxnum)

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

print(ans)

Submission status: Accepted

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

ans = -float("INF")
for bit in range(1 << 10):
    day = []
    for i in range(10):
        if (bit >> i) & 1:
            day.append(i)
    if day == [] or bit == 0:
        continue
    tmp = 0
    for i in range(N):
        c = 0
        for k in day:
            if F[i][k] == 1:
                c += 1
        tmp += P[i][c]
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

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

ans = -10000000000
for bit in range(1, 1<<10):
  now = 0
  for i in range(N):
    c = 0
    for j in range(10):
      if (1&bit>>j) & F[i][j]:
        c += 1
    now += P[i][c]
  ans = max(ans, now)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
f = [list(map(int,input().split())) for i in range(n)]
p = [list(map(int,input().split())) for i in range(n)]
ans = -float("inf")
for i in range(1,2**10):
    now = 0
    for j in range(n):
        cou = 0
        for k in range(10):
            if (i >> k & f[j][k]) == 1:
                cou += 1
        now += p[j][cou]
    ans = max(ans,now)
print(ans)

Submission status: Accepted

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

import itertools

xl = list(itertools.product(range(2), repeat=10))

res = -1*(10**10)

for i in range(1,1024):# 開店パターン
    temp =0
    for j in range(n):#　店の数
        op = 0
        
        for k in range(10):#掛け算して営業タイミング確認
            op += xl[i][k]*fl[j][k] 
        temp += pl[j][op]
    
    res = max(res,temp)
    
print(res)

Submission status: Accepted

Solution code:
n = int(input())
f = []
for i in range(n):
    fi = list(map(int,input().split()))
    f.append(fi)
p = []
for i in range(n):
    t = list(map(int,input().split()))
    p.append(t)
ma = -1 * 10 ** 12
for bit in range(1024):
    count = 0
    countc = 0
    for i in range(n):
        countb = 0
        for j in range(10):
            if bit >> j & 1 and f[i][j] == 1:
                countb+=1
                countc+=1
        count+= p[i][countb]
    if countc == 0:
        continue
    ma = max(ma,count)
print(ma)

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

Submission status: Accepted

Solution code:
n = int(input())
f = [list(map(int,input().split())) for i in range(n)]
p = [list(map(int,input().split())) for i in range(n)]
ans = -float("inf")
for i in range(1,2**10):
    now = 0
    for j in range(n):
        cou = 0
        for k in range(10):
            if (i >> k & f[j][k]) == 1:
                cou += 1
        now += p[j][cou]
    ans = max(ans,now)
print(ans)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
F = []
for i in range(N):
    f = list(map(str, input().split()))
    bi = ''.join(f)
    F.append(int(bi, 2))
P = []
for i in range(N):
    p = getList()
    P.append(p)

# -modに!!
ans = -mod
for bit in range(1, 1 << 10):
    cnt = 0
    for j in range(N):
        open = bit & F[j]
        index = str(bin(open)).count('1')
        # print(P[i][index])
        cnt += P[j][index]
    ans = max(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

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

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

print(ans)