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())         
import numpy as np

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

max_p = -999999999999
                     
for j in range(1,2**10):  
  store = [0,0,0,0,0,0,0,0,0,0] 
  flag = True          
  for k in range(10):  
    if j %2 ==1 : 
      store[k] = 1 
    j = int(j/2)                           
#store = np.array([1,0,1,0,0,0,0,0,0,0]) 
  days = [sum(i) for i in store * open] 
  score = 0                            
  for i in range(n):                   
          score += p[i][days[i]]
  if score > max_p: 
    max_p = score            
print(max_p)

Submission status: Accepted

Solution code:
import itertools
inf = float('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 shift in itertools.product([0,1],repeat=10):
    if not any(shift): continue
    res = 0
    for i,line in enumerate(F):
        c = 0
        for s, f in zip(shift, line):
            if s and f:
                c += 1
        res += P[i][c]
    if res > ans:
        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 = - 10**18

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

print(ans)

Submission status: Accepted

Solution code:
I=input;n=int(I());f=eval('int(I()[::2],2),'*n);p=eval('I().split(),'*n);print(max(sum(int(q[bin(i&g).count('1')])for g,q in zip(f,p))for i in range(1,1024)))

Submission status: Accepted

Solution code:
from numpy import*
n=int(input())
f=array([list(map(int,input().split()))for i in range(n)])
p=array([list(map(int,input().split()))for i in range(n)])
print(max(sum(p[k][v]for k,v in enumerate(sum(f*array([i>>j&1for j in range(10)]),axis=1)))for i in range(1,1024)))

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


def D2NC(D: int, N: int) -> list:
    res = []
    while D > 0:
        res.insert(0, D % N)
        D //= N
    if not res:
        res.append(0)
    return res


ans = -10**9
for i in range(1, 2**10):
    pattern = ''.join([str(j) for j in D2NC(i, 2)]).zfill(10)
    idx = 0
    ct = 0
    count = [0 for i in range(N)]
    for j in pattern:
        if j == '1':
            idx_2 = 0
            for k in F:
                if k[idx] == 1:
                    count[idx_2] += 1
                idx_2 += 1
        idx += 1
    pro = 0
    for j in range(N):
        pro += P[j][count[j]]
    ans = max(ans, pro)

print(ans)

Submission status: Accepted

Solution code:
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)
    ]

    ans = f(N, F, P)
    print(ans)


def f(N, F, P):
    """
    N=100=10^2
    曜日*AMPM=10
        Fの組合せ=2^10≒1000=10^3
    10^3*10^2=10^5
    """
    ans = -float("inf")
    for x in range(1, 2 ** 10):
        tmp = 0
        for i in range(N):
            c = 0
            for j in range(10):
                # bit onと店営業中の確認
                if x & (2 ** j) and F[i][j]:
                    c += 1
            tmp += P[i][c]

        ans = max(ans, tmp)

    return ans


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))


n = II()
eigyo_times = [LI() for _ in range(n)]
p = [LI() for _ in range(n)]
bits = []

# それぞれの時間帯で営業するorしないを全探索しても2^10通り
for i in range(2 ** 10):
    op = [0] * 10
    for j in range(10):
        if ((i >> j) & 1):
            op[10-1-j] = 1
            bits.append(op)

profit = -(10**100)
for i, bit in enumerate(bits):
    if bit == [0,0,0,0,0,0,0,0,0,0]:  # 1つ以上の時間帯で店を営業しなければならない
        continue
    tmp_profit = 0
    for j, eigyo_time in enumerate(eigyo_times):
        # joisinoお姉ちゃんと店両方が営業している時間帯の個数を求める
        count = len([k for k in range(10) if bit[k] & eigyo_time[k]])
        tmp_profit += p[j][count]
    profit = max(profit, tmp_profit)
print(profit)

Submission status: Accepted

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

ans = -10000000000
for i in range(1, 1024):
    anstemp = 0
    open = "{:010b}".format(i)
    for j in range(N):
        count = 0
        for k in range(10):
            if open[k] == "1" and shop[j][k] == 1:
                count += 1
        anstemp += prof[j][count]
    ans = max(ans, anstemp)
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 j in range(1,2**10):
  A=list(str(bin(j))[2:])
  for i in range(10-len(A)):
    A.insert(0,"0")  
  prof=0
  for i in range(n):
    k=sum(int(p)*q for p,q in zip(A,F[i]))
    prof+=P[i][k]
  ans=max(ans,prof)
print(ans)

Submission status: Accepted

Solution code:

n = int(input())

F = []
P = []
for i in range(n):
  f = int(input().replace(" ", ""), 2)#2進数で保持
  F.append(f)
  
for i in range(n):
  p = list(map(int,input().split()))
  P.append(p)
  
ans = -10 ** (7+2)

for i in range(1, 2**10):
  total_income = 0
  for j, income in enumerate(P):
    num = bin(i & F[j]).count("1")
    total_income += income[num]

  ans = max(ans,total_income)

  
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N = ii()
F = [[0] * 10 for _ in range(N)]
for i in range(N):
    F[i] = lmi()


P = [[-10**9 for _ in range(10)] for _ in range(N)]
for i in range(N):
    P[i] = lmi()

# print(F)
rieki = -10**18
for i in range(1, 2 ** 10):  # bit全探索
    tmprieki = 0
    for num in range(N):
        cnt = 0
        for j in range(10):
            if ((i >> j) & 1) and F[num][j] == 1:
                cnt += 1
        tmprieki += P[num][cnt]
    rieki = max(rieki, tmprieki)

print(rieki)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,a,b = LI()
    print(min(n*a,b))
    return

#B
def B():
    s = S()
    print(s.count("1"))
    return

#C
def C():
    n = list(map(int, S()))
    k = 0
    s = sum(n)
    for i in range(len(n)):
        k *= 10
        k += n[i]
    if k%s == 0:
        print("Yes")
    else:
        print("No")
    return

#D
def D():
    n = I()
    a = LI()
    ans = float("inf")
    for i in range(n):
        m = 0
        while a[i]%2 == 0:
            m += 1
            a[i] //= 2
        ans = min(m,ans)
    print(ans)
    return

#E
def E():
    def dfs(n,k):
        if n == 10:
            l.append(k)
        else:
            dfs(n+1,k+[0])
            dfs(n+1,k+[1])
    n = I()
    f = LIR(n)
    p = LIR(n)
    l = []
    dfs(0,[])
    ans = -float("inf")
    for k in l[1:]:
        m = 0
        c = [0 for i in range(n)]
        for i in range(n):
            for j in range(10):
                c[i] += f[i][j]&k[j]
            m += p[i][c[i]]
        ans = max(m,ans)
    print(ans)
    return

#F
def F():
    n,k = LI()
    a = LI()
    d = defaultdict(int)
    for i in a:
        d[i] += 1
    d = list(d.values())
    d.sort()
    ans = 0
    for i in range(len(d)-k):
        ans += d[i]
    print(ans)
    return

#G
def G():
    n,c = LI()
    ch = LIR(n)
    T = [[0 for i in range(100002)] for j in range(c+1)]
    for s,t,cha in ch:
        T[cha-1][s] += 1
        T[cha-1][t+1] -= 1
    for i in range(c):
        for j in range(100000):
            T[i][j+1] += T[i][j]
            if T[i][j] >= 1:
                T[i][j] = 1
    ans = 0
    for i in range(100001):
        m = 0
        for j in range(c+1):
            m += T[j][i]
        ans = max(m,ans)
    print(ans)
    return

#H
def H():
    n = I()
    a = LI()
    ma = a.index(max(a))
    mi = a.index(min(a))
    ans = []
    if abs(a[ma]) > abs(a[mi]):
        ans.append([ma+1,1])
        ans.append([ma+1,1])
        a[0] += 2*a[ma]
        for i in range(n-1):
            ans.append([i+1,i+2])
            ans.append([i+1,i+2])
            a[i+1] += 2*a[i]
    else:
        ans.append([mi+1,n])
        ans.append([mi+1,n])
        a[-1] += 2*a[mi]
        for i in range(n-1)[::-1]:
            ans.append([i+2,i+1])
            ans.append([i+2,i+1])
            a[i] += 2*a[i+1]
    print(len(ans))
    for i in ans:
        print(*i)
    return

#I
def I_():
    n = I()
    print(1080/(n-1))
    return

#J
def J():
    h,w,n = LI()
    p = LIR(n)
    if n%2 == 1:
        print(-1)
        quit()
    ans = []
    for i in range(1,h+1):
        c = 0
        m = i/w
        for x,y in p:
            if m*x < y:c += 1
            elif m*x == y:
                c = 0
                break
        if c == n//2:
            ans.append([w,i])

    for i in range(1,w):
        c = 0
        m = h/i
        for x,y in p:
            if m*x < y:c += 1
            elif m*x == y:
                c = 0
                break
        if c == n//2:
            ans.append([i,h])
    if len(ans) == 0:
        print(-1)
        quit()
    ans.sort()
    for x,y in ans:
        print("("+str(x)+","+str(y)+")")
    return

#K

#L
def L():
    return

#M
def M():
    return


#Solve
if __name__ == "__main__":
    E()

Submission status: Accepted

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

from itertools import combinations

mm = None
for i in range(1, 11):
  for ss in combinations(range(0, 10), i):
    m = 0
    for j in range(N):
      c = sum(f for k, f in enumerate(FF[j]) if k in ss)
      m += PP[j][c]
    if mm is None:
      mm = m
    else:
      mm = max(mm, m)
print(mm)

Submission status: Accepted

Solution code:
n=int(input());f,p=[],[];ans=""
for _ in range(n):f.append(list(map(int,input().split())))
for _ in range(n):p.append(list(map(int,input().split())))
for i in range(1,2**10):
  s=bin(i)[2:].zfill(10);a=0
  for j in range(n):
    m=0
    for h in range(10):
      if s[h]=="1":m+=f[j][h]
    a+=p[j][m]
  ans=(a if ans==""else max(ans,a))
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**9
for i in range(1,2**10):
  a=0
  m=[i%2,i//2%2,i//4%2,i//8%2,i//16%2,i//32%2,i//64%2,i//128%2,i//256%2,i//512%2]
  mm=[0 for i in range(n)]
  for i in range(10):
    for j in range(n):
      if m[i]==1 and f[j][i]==1:
        mm[j]+=1
  for i in range(n):
    a+=p[i][mm[i]]
  ans=max(ans,a)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
fn = [list(map(int,input().split())) for _ in range(N)]
pn = [list(map(int,input().split())) for _ in range(N)]
bitf = []
for i in range(N):
    temp = 0
    for j in range(10):
        temp += ((2 ** j) * fn[i][j])
    bitf.append(temp)
#print(bitf)
def func(x , y):
    return bin(x & y).count('1')
ans = (-1) * 10 ** 10
for i in range(1,2**10):
    temp = 0
    for j in range(N):
        temp += pn[j][func(i,bitf[j])]
    ans = max(ans , temp)
print(ans)

Submission status: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict, Counter
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

N = i_inpl()
F = []
for _ in range(N):
    Fi = l_inpl()
    F.append(Fi)

P = []
for _ in range(N):
    Pi = l_inpl()
    P.append(Pi)


# bit全探索
ans = -1 * INF
for i in range(1, 2**10):
    tmp = 0
    for j in range(N):
        c = 0
        # NOTE: iとF[j]のAND演算
        for k in range(10):
            if ((i>>k) & 1) & F[j][k]:
                c += 1
        tmp += P[j][c]
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

bits = []
for i in range(n):
  bit = int(input().replace(" ", ""), 2)
  bits.append(bit)
p = [[int(item) for item in input().split()] for _ in range(n)]

ans = - 10**9
for i in range(1,2**10):
  val = 0
  for j,mise in enumerate(p):
    val += mise[bin(i & bits[j]).count("1")]
  ans = max(ans, val)
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**7) * 10 * 100

for i in range(1,2**10):  
  counter = [0]*N #店iとjoisinoのかぶっている数
  tmp = 0 #  
  for j in range(10):    
    if (i>>j) & 1:
      for k in range(N):
        if F[k][j] ==1:
          counter[k] += 1
  for l in range(N):
    tmp += P[l][counter[l]]
      #tmp += P[k][counter[k]]
  ans = max(tmp,ans)
print(ans)

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N = I()
F = []
for i in range(N):
    F.append(LI())
P = []
for i in range(N):
    P.append(LI())

"""
各時間帯をon/offで2通り全探索すると、2**10になる。
"""
ans = -10**18
def dfs(l):
    global ans
    if len(l) == 10:
        if all(item == 0 for item in l):
            return
        # 探索終了
        point = 0
        for n in range(N):
            s = sum([f for fidx, f in enumerate(F[n]) if f == l[fidx] == 1])
            point += P[n][s]
        ans = max(ans, point)
        return
    dfs(l + [0])
    dfs(l + [1])

dfs([])
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000)

N=int(input())
count=[]
F=[list(map(int,input().split())) for i in range(N)]
P=[list(map(int,input().split())) for i in range(N)]
INF=10**9

def dfs(s):
    if len(s)==10:
        if "1" not in s:
            val=-INF
        if "1" in s:
            val=0
            c=[0 for i in range(N)]
            for i in range(N):
                #F1 F2
                count=0
                for j in range(10):
                    
                    if int(int(s[j])*F[i][j]):
                        c[i]+=1
                    #print("count",count)

            for i in range(N):
                val+=P[i][c[i]]
        return val
    else:
        return max(dfs(s+"0"),dfs(s+"1"))
print(dfs(""))

Submission status: Accepted

Solution code:
n = int(input())

bits = []
for i in range(n):
    bit = int(input().replace(" ", ""), 2)
    bits.append(bit)
p = [[int(item) for item in input().split()] for _ in range(n)]

ans = - 10**9
for i in range(1,2**10):
    val = 0 
    for j, mise in enumerate(p):
        val += mise[bin(i & bits[j]).count("1")]
    ans = max(ans, val)

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

B=[bin(i)[2:] for i in range(1024)]
for i in range(len(B)):
    while(len(B[i])<10):
        B[i]="0"+B[i]
c=0
ans=-10**9
for b in B[1:]:
    res=0
    for index,f in enumerate(F):
        #print('f',f)
        for i,j in zip(f,b):
            if(str(i)==j and i==1):
                c+=1
        #print(b,"のときのc:",c)
        #print("p",P[index][c])
        res+=P[index][c]
        c=0
    ans=max(ans,res)
print(ans)

Submission status: Accepted

Solution code:
import itertools

def main():
    n = int(input())

    ans = -10 ** 9
    f = [[0 for i in range(10)] for j in range(n)]
    p = [[0 for i in range(11)] for j in range(n)]

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

    ans = -float("inf")
    for i0, i1, i2, i3, i4, i5, i6, i7, i8, i9 in itertools.product(range(2), range(2), range(2),range(2), range(2), range(2),range(2), range(2), range(2), range(2)):
        i_list = [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9]
        if sum(i_list) != 0:
            value = 0
            for j in range(n):
                value += p[j][sum([i_list[_]*f[j][_] for _ in range(10)])]
            ans = max(ans, value)

    print(ans)


main()

Submission status: Accepted

Solution code:
n = int(input())
f = [input().split(' ') for _ in range(n)]
p = [input().split(' ') for _ in range(n)]
res = -10 ** 7 * n
for num in range(1, 1024):
  tmp = 0
  for index in range(0, n):
    tmp += int(p[index][len([True for x in range(0, 10) if f[index][x]=='{:010b}'.format(num)[x]=='1'])])
  res = max(tmp, res)
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):
    t = 0
    for j in range(N):
        c = 0
        for k in range(10):
            c += ((i >> k) & 1) & F[j][k]
        t += P[j][c]
    ans = max(ans, t)
print(ans)

Submission status: Accepted

Solution code:
import itertools

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

ans = -float("inf")
for pattern in itertools.product(range(2), repeat=10):
  if sum(pattern)==0:
    continue

  tmp_ans = 0
  for mise_i in range(n):
    tmp_cnt = 0
    for i,ptn in enumerate(pattern):
      if ptn == 1 and f[mise_i][i] == 1:
        tmp_cnt += 1
    tmp_ans += p[mise_i][tmp_cnt]
  if tmp_ans > ans:
    ans = tmp_ans
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())))
inf=1<<60
ans=-inf
for t in range(1,2**10):
    a=0
    for i in range(N):
        c=0
        for j in range(10):
            if F[i][j]==1 and (t & (1<<j)) != 0:
                c+=1
        a+=P[i][c]
    ans=max(ans,a)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
Open=[list(map(int,input().split())) for i in range(N)]
Profit=[list(map(int,input().split())) for i in range(N)]
ans=-1*float('inf')
for x in range(1,2**10):
    check=bin(x)[2:]
    check='0'*(10-len(check))+check
    now=0
    for i in range(N):
        cnt=0
        for k in range(10):
            if int(check[k])*Open[i][k]==1:
                cnt+=1
        now+=Profit[i][cnt]
    ans=max(ans,now)
print(ans)

Submission status: Accepted

Solution code:
def base10to(n, b):
    if (int(n/b)):
        return base10to(int(n/b), b) + str(n % b)
    return str(n % b)


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 = []
for i in range(1,1024):
    lis = list(base10to(i, 4).zfill(5))
    temp = 0
    for k in range(N):
        count = 0
        for j in range(len(lis)):
            if lis[j] == '0':
                count += f[k][2*j]*0 + f[k][2*j + 1]*0
            elif lis[j] == '1':
                count += f[k][2*j]*1 + f[k][2*j + 1]*0
            elif lis[j] == '2':
                count += f[k][2*j]*0 + f[k][2*j + 1]*1
            elif lis[j] == '3':
                count += f[k][2*j]*1 + f[k][2*j + 1]*1
        temp += p[k][count]
    ans.append(temp)
print(max(ans))

Submission status: Accepted

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

ans = -10 ** 10

def calc(b):
    p = 0
    for i in range(N):
        c = 0
        for j in range(10):
            c += F[i][j] * b[j]
        p += P[i][c]
    return p

def dfs(b):
    global ans
    if len(b) == 10:
        if max(b) == 0:
            return
        ans = max(ans, calc(b))
        return
    dfs(b + [0])
    dfs(b + [1])

dfs([0])
dfs([1])
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 ** 10
for b in range(1, 2 ** 10):
    bin_str = format(b, '010b')
    p = 0
    for i in range(N):
        c = 0
        for j in range(10):
            c += F[i][j] * int(bin_str[j])
        p += P[i][c]
    ans = max(ans, p)
print(ans)

Submission status: Accepted

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

INF=10**9
ans=-INF

for i in range(1,2**10):
    tmpans=0
    for n in range(N):
        c=0
        for j in range(10):
            if (i>>j&1)&F[n][j]:
                c+=1
        tmpans+=P[n][c]

    ans=max(ans,tmpans)

print(ans)

Submission status: Accepted

Solution code:
def solve(string):
    n, *fp = map(int, string.split())
    f = "".join(map(str, fp[:10 * n]))
    p = fp[10 * n:]
    int_f = [int(f[10 * i:10 * (i + 1)], 2) for i in range(n)]
    return str(
        max(
            sum([p[11 * i + bin(o & _f).count("1")]
                 for i, _f in enumerate(int_f)])
            for o in range(1, 2**10)))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(2 * n)])))

Submission status: Accepted

Solution code:
def solve(string):
    n, *fp = string.split()
    n = int(n)
    f = fp[:10 * n]
    p = list(map(int, fp[10 * n:]))
    int_f = [int("".join(f[10 * i:10 * (i + 1)]), 2) for i in range(n)]
    return str(
        max(
            sum([p[11 * i + bin(o & _f).count("1")]
                 for i, _f in enumerate(int_f)])
            for o in range(1, 2**10)))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(2 * n)])))

Submission status: Accepted

Solution code:
def solve(string):
    n, *fp = string.split()
    n = int(n)
    f = fp[:10 * n]
    p = list(map(int, fp[10 * n:]))
    ans = -n * 10**7
    int_f = [int("".join(f[10 * i:10 * (i + 1)]), 2) for i in range(n)]
    for o in range(1, 2**10):
        tmp = [sum(map(int, "{:b}".format(o & _f))) for _f in int_f]
        ans = max(ans, sum([p[11 * i + t] for i, t in enumerate(tmp)]))
    return str(ans)


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(2 * n)])))

Submission status: Accepted

Solution code:
from itertools import product
import numpy as np


def solve(string):
    n, *fp = map(int, string.split())
    # f = np.asarray(fp[:10 * n]).reshape((n, 10))
    f = fp[:10 * n]
    p = fp[10 * n:]
    ans = -n * 10**7
    """
    for o in product([0, 1], repeat=10):
        if sum(o) == 0:
            continue
        # tmp = np.dot(f, np.asanyarray(o).T)
        tmp = [sum([for ]) for _f in f]
        ans = max(ans, sum([p[11 * i + t] for i, t in enumerate(tmp)]))
    return str(ans)
    """
    int_f = [int("".join(map(str, f[10 * i:10 * (i + 1)])), 2) for i in range(n)]
    for o in range(1, 2**10):
        tmp = [sum(map(int, "{:b}".format(o & _f))) for _f in int_f]
        ans = max(ans, sum([p[11 * i + t] for i, t in enumerate(tmp)]))
    return str(ans)


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(2 * n)])))

Submission status: Accepted

Solution code:
from itertools import product
import numpy as np


def solve(string):
    n, *fp = map(int, string.split())
    f = np.asarray(fp[:10 * n]).reshape((n, 10))
    p = fp[10 * n:]
    ans = -n * 10**7
    for o in product([0, 1], repeat=10):
        if sum(o) == 0:
            continue
        tmp = np.dot(f, np.asanyarray(o).T)
        ans = max(ans, sum([p[11 * i + t] for i, t in enumerate(tmp)]))
    return str(ans)


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(2 * n)])))

Submission status: Accepted

Solution code:
n = int(input())

f = []

for i in range(n):
    f.append(list(map(int,input().split())))
c = []
for i in range(n):
    c.append(list(map(int,input().split())))
res = -10**19
for i in range(1,1024):
    s = format(i,'#012b')[2:]
    money = 0
    for k in range(n):
        acc = 0
        for j in range(10):
            acc += f[k][j] and int(s[j])
        #print(acc,end="")
        money += c[k][acc]
    #print(money)
    res = max(res,money)
print(res)

Submission status: Accepted

Solution code:
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
INF = float("inf")

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

ans = -INF
for i in range(1,1024):
    profit = 0
    for j in range(n):
        cnt = 0
        for x in range(10):
            if (i >> x) %2 == 1 and F[j][x] == 1:
                cnt += 1
        profit += P[j][cnt]
    ans = max(ans,profit)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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):  # 2 ** 10 == 1024
    fund = 0
    for i in range(n):  # 店の数
        cou = 0  # かぶる数
        for x in range(10):  # 月-金(5) * 2
            if (item >> x) % 2 == 1 and arr[i][x] == 1:  # その時間で被るかどうか
                cou += 1
        fund += arm[i][cou]
    ans = max(ans, fund)  # 最大値更新

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
shop=[]
profit=[]
for i in range(n):
  k=list(map(int,input().split()))
  shop.append(k)
for i in range(n):
  k=list(map(int,input().split()))
  profit.append(k)
def dfs(i,flag):
  if i!=10:
    return max(dfs(i+1,flag),dfs(i+1,flag|2**i))
  if flag==0:
    return -10**18
  prof=0
  store=[0]*n
  for j in range(10):
    if (flag)&(2**j)>0:
      for k in range(n):
        store[k]+=shop[k][j]
  for k in range(n):
    prof+=profit[k][store[k]]
  return prof
print(dfs(0,0))

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 j in range(N)]
m = -float("INF")
for i in range(1, 1024):
    n = 0
    for j in range(N):
        c = 0
        for k in range(10):
            if i >> k & 1:
                if F[j][k] == 1:
                    c += 1
        n += P[j][c]
    m = max(m, n)
print(m)