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: Wrong Answer

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

for t in range(1,1024):
  bits = list(bin(t))
  a = [0 for _ in range(n)]
  jk = 0
  while jk < 10:
    b = bits.pop()
    if b == "b":
      break
    elif b == "0":
      jk += 1
      continue
    else:
      for i in range(n):
        if f[i][jk]:
          a[i] += 1
  
  s = 0
  for i in range(n):
    s += p[i][a[i]]
  else:
    benefits.append(s)
else:
  print(max(benefits))

Submission status: Wrong Answer

Solution code:
num = int(input())

array = []
for i in range(0, num):
    array.append([int(x) for x in input().split()])

array2 = []
for j in range(0, num):
    array2.append([int(x) for x in input().split()])

res_array = []
for k in range(0, len(array2)):
    res_array.append(array2[k][:array[k].count(1)+1])

res = 0
judge = 0
for l in res_array:
    if l[0] == max(l) and l.count(l[0]) == 1:
        judge += 1
    res += max(l)
if judge == len(res_array):
    tmp_array = []
    for m in res_array:
        tmp_array += m[1:]
        res = min(tmp_array)
print(res)

Submission status: Wrong Answer

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 = -123456789
for mask in range(1,2**10):
    tmp = 0
    for i in range(n):
        cnt = 0
        for x in range(10):
            if (mask>>x) % 2 == 1 and f[i][x] == 1: cnt += 1
        tmp += p[i][cnt]
    ans = max(ans, tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
num = int(input())

array = []
for i in range(0, num):
    array.append([int(x) for x in input().split()])

array2 = []
for j in range(0, num):
    array2.append([int(x) for x in input().split()])

res_array = []
for k in range(0, len(array2)):
    res_array.append(array2[k][:array[k].count(1)+1])

res = 0
judge = 0
for l in res_array:
    if l[0] == max(l):
        judge += 1
    res += max(l)
if judge == len(res_array):
    tmp_array = []
    for m in res_array:
        tmp_array += m[1:]
        res = min(tmp_array)
print(res)

Submission status: Wrong Answer

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 = -123456789
for mask in range(1,2**10):
    tmp = 0
    updated = False
    for i in range(n):
        cnt = 0
        for x in range(10):
            if (mask>>x) % 2 == 1 and f[i][x] == 1: cnt += 1
        tmp += p[i][cnt]
        if cnt > 0 : updated = True
    if updated: ans = max(ans, tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product

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


max_res = -10**7-1


for i,j in enumerate(product("01",repeat=10)):
    if i != 0:
        res = [0 for _ in range(N)]
        for k, flag in enumerate(j):
            if flag == "1":
                for l,f in enumerate(F):
                    if f[k] == "1":
                        res[l] += 1
        buf = 0
        for m in range(N):
            buf += int(P[m][res[m]])
        max_res = max(buf,max_res)

print(max_res)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
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)]

cnt = [0] * N
for i in range(N):
    for j in range(10):
        if F[i][j] == 1:
            cnt[i] += 1

s = [0] * N
for i in range(N):
    for j in range(N):
        s[i] += max([x for x in ((P[j])[1:cnt[j] + 1] if (i == j) else (P[j])[:cnt[j] + 1])])

print(max(s))

Submission status: Wrong Answer

Solution code:
import sys
import math
from operator import add

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(' '))))
maxprofit = -100000
for i in range(1, 1024):
    binstr = bin(i) 
    original = list(map(int, binstr[2:]))
    original = [0]*(10-len(original)) + original
    profit = 0
    for j in range(N):
        s = [a+b for (a, b) in zip(original, F[j])]
        dup = len([a for a in s if a == 2])
        profit += P[j][dup]
    if maxprofit < profit:
        maxprofit = profit
print(maxprofit)

Submission status: Wrong Answer

Solution code:
from itertools import product
def inpl(): return map(int, input().split())

N = int(input())
F = [tuple(inpl()) for _ in range(N)]
P = [tuple(inpl()) for _ in range(N)]

result = -1 * 10**8
for T in product([0, 1], repeat=10):
    if sum(T) == 0:
        continue
    tmp = 0
    for i in range(N):
        c = sum([f*t for f, t in zip(F[i], T)])
        tmp += P[i][c]
    result = max(result, tmp)
print(result)

Submission status: Wrong Answer

Solution code:
N=int(raw_input())

f=[]
for _ in range(N):
  f.append(map(int,raw_input().split(' ')))

p=[]
for _ in range(N):
  p.append(map(int,raw_input().split(' ')))

s=float('-inf')
for t in range(1,1023):
  l=map(int,list(bin(t)[2:].zfill(10)))
  tmp=0
  for i in range(N):
    c=0
    for t in range(10):
      if l[t]==0:
        continue
      if f[i][t]:
        c+=1

    tmp+=p[i][c]

  if tmp>s:
    s=tmp
    
print s

Submission status: Wrong Answer

Solution code:
import itertools

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

best = -100000000
for i in range(1, 11):
    for x in itertools.combinations(range(0, 10), i):
        sum = 0
        for j in range(n):
            fs = 0
            for k in x:
                if f[j][k] == 1: fs += 1
            sum += p[j][fs]
        if sum > best:
            best = sum
print best

Submission status: Time Limit Exceeded

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

if N == 2:
  while True:
    print("yeah")
#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: Time Limit Exceeded

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 row in product([0, 1], repeat=10):
    tmp = 0
    open_num = 0
    for ind, Fi in enumerate(F):
        open_num += np.logical_and(np.array(row), np.array(Fi)).sum()
        tmp += P[ind][np.logical_and(np.array(row), np.array(Fi)).sum()]
    if tmp > ans and open_num>0:
        ans = tmp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools


def solve():
    N = int(input())
    F = []
    cnt_of_1 = []
    for _ in range(N):
        tmp_F = list(map(int, input().split(" ")))
        cnt_of_1.append(tmp_F.count(1))
        F.append(tmp_F)
    P = []
    zero_cmb = []
    for _ in range(N):
        tmp_P = list(map(int, input().split(" ")))
        zero_cmb.append(tmp_P[0])
        P.append(tmp_P)

    for i in range(N):
        P[i] = P[i][:cnt_of_1[i] + 1]

    cmb = list(itertools.product(*P))
    target = cmb.index(tuple(zero_cmb))
    del cmb[target]
    maximum = -1000000000
    for ele in cmb:
        maximum = max(maximum, sum(ele))

    print(maximum)
    

solve()

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
lsF = [[]]
for i in range(N):
    lsF.append(list(map(int,input().split())))
lsP = [[]]
for i in range(N):
    lsP.append(list(map(int,input().split())))
bita = list(product(range(2),repeat=10))
bita.pop(0)
ans = -10**10
for bit in bita:
    count = [0 for i in range(N+1)]
    for i in range(10):
        for j in range(1,N+1):
            count[j] += bit[i]*lsF[j][i]
    benifit = 0
    for i in range(1,N+1):
        benifit += lsP[i][count[i]]
    ans = max(ans,benifit)
print(ans)

Submission status: Accepted

Solution code:
import itertools
n=int(input())
f=[list(map(int,input().split())) for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(n)]
ans=-(10**12)
for i in range(1,11):
    num=list(itertools.combinations(range(10),i))
    for j in range(len(num)):
        cnt=[0]*n
        cnt2=0
        for k in range(i):
            for l in range(n):
                if f[l][num[j][k]]==1:
                    cnt[l]+=1
        for k in range(n):
            cnt2+=p[k][cnt[k]]
        ans=max(cnt2,ans)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import numpy as np
from itertools import product
import sys
sys.setrecursionlimit(10**6)

n = int(input())

data = np.zeros((10, n), dtype=int)
for i in range(n):
    f = np.array(list(map(int, input().split())))
    data[:, i] = f

# print(data)

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

ans = -10**10

for j, i in enumerate(product([0, 1], repeat=10)):
    if j == 0:
        continue

    indices = [x for x, y in enumerate(i) if y == 1]
    # print(indices)

    data_tmp = data[indices]
    data_tmp = np.sum(data_tmp, axis=0)
    ans_tmp = sum([p[a][b] for a, b in enumerate(data_tmp)])
    ans = max(ans, ans_tmp)
print(ans)

Submission status: Accepted

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

def solve(out_list):
  ans = 0
  for fi, pi in zip(f, p):
    c = 0
    for o in out_list:
      if fi[o] == 1:
        c += 1
    ans += pi[c]
  return ans

ans = -float("inf")
for i in range(2 ** 10):
  out_list = []
  ## どの桁が1になっているかをチェックするために2進数の各桁をループ
  for j in range(10):
    ## i >> jで確認したい桁を一番右までずらして1と論理積をとって「選択」している要素を確認
    if (i >> j) & 1:
      out_list.append(j)
  if len(out_list) != 0:
    ans = max(ans, solve(out_list))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
F = [0]*n
P = [0]*n
for i in range(n):
    F[i] = list(map(int,input().split()))
for i in range(n):
    P[i] = list(map(int,input().split()))
 
ans = -float("Inf")
for i in range(1,2**10):
    L = []
    b = 0
    for j in range(10):
        if (i>>j)&1:
            L.append(j)
    for j in range(n):
        c = 0
        for x in L:
            if F[j][x] == 1:
                c += 1
        b += P[j][c]
        
    ans = max(ans, b)
 
 
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(2**10-1):
  Bit = [1]*10
  for j in range(10):
    if (i>>j)&1:
      Bit[j]=0
  count = 0
  for k in range(N):
    op = sum(b&f for b,f in zip(Bit,F[k]))
    count+=P[k][op]
  ans = max(ans,count)
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**10

for a in range(2**10):
    t = [(a>>b)&1 for b in range(10)]
    if 1 not in t:
        continue
    
    p = 0
    for i in range(N):
        p += P[i][sum(t[j] and F[i][j] for j in range(10))]

    ans = max(p, ans)

print(ans)

Submission status: Accepted

Solution code:
import itertools

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

ans = -10 ** 10
flg = True
for lst in itertools.product(range(2), repeat = 10):
    if flg:
        flg = False
        continue
    ans_sub = 0
    for i in range(n):
        cnt = sum(j * k for j, k in zip(lst, F_s[i]))
        ans_sub += P_s[i][cnt]
    ans = max(ans, ans_sub)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

ans = -10**32
 
for k in range(1,1<<10):
    sc = 0
    
    for i in range(n):
        cnt = 0
        for j in range(10):
            if L[i][j] and k>>j&1:
                cnt +=1
        #print(L[i],v,cnt,i,score,score[i][cnt])
        sc += score[i][cnt]
            #print(L[i],v,cnt,i,score,score[i][cnt])
    ans = max(ans,sc)

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

max_prof = -float('inf')

for s in range(1, 1 << 10):

    sum_prof = 0
    for store_no in range(N):
        state = s

        time_zone = 0
        both_open_cnt = 0
        while state > 0:
            if (state & 1) and F[store_no][time_zone]:
                both_open_cnt += 1

            state >>= 1
            time_zone += 1

        sum_prof += P[store_no][both_open_cnt]

    max_prof = max(max_prof, sum_prof)


print(max_prof)

Submission status: Accepted

Solution code:
from itertools import combinations

def getval():
    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)]
    return n,f,p

def main(n,f,p):
    ans = 0
    for i in range(n):
        temp = 0
        for j in f[i]:
            temp += j
        ans += p[i][temp]

    for i in range(1,10):
        for c in combinations(range(10),i):
            pro = 0
            for j in range(n):
                temp = 0
                for k in c:
                    temp += f[j][k]
                pro += p[j][temp]
            ans = max(ans,pro)

    print(ans)

if __name__=="__main__":
    n,f,p = getval()
    main(n,f,p)

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=-1000000000
for i in range(1,1<<10):
    cnt=[0 for _ in range(N)]
    for j in range(10):
        if (i>>j)%2==1:
            for k in range(N):
                cnt[k]+=F[k][j]
    A=[P[j][cnt[j]] for j in range(N)]
    ans=max(ans,sum(A))
print(ans)

Submission status: Accepted

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

ans = -100000000000
for k in range(1, 2 ** 10):
    val = 0
    for i in range(N):
        c = bin(k & F[i]).count("1")
        val += P[i][c]
    ans = max(ans, val)
print(ans)

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

######################################################

N=intput()
F=[lint() for _ in range(N)]
P=[lint() for _ in range(N)]
ans=-INF
for c in product([0,1],repeat=10):
    if c==(0,0,0,0,0,0,0,0,0,0):
        continue
    tmp=0
    for i in range(N):
        count=0
        for j in range(10):
            count+=c[j]&F[i][j]
        tmp+=P[i][count]
    ans=max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
F = [int("".join(input().split()), 2) for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(n)]
num = 1 << 10
ans = -(10 ** 10)


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


# print(F)

for i in range(1, num):
    temp = 0
    for j in range(n):
        temp += P[j][popcnt(i & F[j])]
    ans = max(temp, ans)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

def main():
    with open(0) as f:
        N = int(f.readline())
        F = np.array([list(map(int, f.readline().split())) for _ in range(N)])
        P = [list(map(int, f.readline().split())) for _ in range(N)]

    max_profit = -np.inf
    for i in range(1,2**10):
        Open = np.array([(i>>j)&1 for j in range(10)])
        conflict = np.dot(F, Open.T)
        profit = sum(P[i][v] for i,v in enumerate(conflict))
        max_profit = max(max_profit, profit)
    print(max_profit)

main()

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())))
a=0
ans=-(10**10)
for k in range(1,1024):
    a=0
    x=bin(k)
    y=[0]*10
    for i in range(2,len(x)):
        y[10-len(x)+i]+=int(x[i])
    for i in range(n):
        m=0
        t=0
        for j in range(10):
            if y[j]+f[i][j]==2:
                t+=1
        m+=p[i][t]
        a+=m
    ans=max(a,ans)
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):
    s = i
    b = [0]*10
    for j in range(10):
        if s >= (2**(10-j-1)):
            s -= 2**(10-j-1)
            b[j] = 1
    a = 0
    for j in range(N):
        c = 0
        for k in range(10):
            if b[k] == 1 and F[j][k] == 1:
                c += 1
        a += P[j][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
for i in range(2**10-1):
    Bit=[1]*10
    for j in range(10):
        if (i>>j)&1:
            Bit[j]=0
    count=0
    for k in range(N):
        op=sum(b&f for b,f in zip(Bit,F[k]))
        count+=P[k][op]
    ans=max(ans,count)
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):
    tf = [False]*10
    for j in range(10):
        if (i>>j)&1:
            tf[j] = True
    cnt1 = 0
    for j in range(n):
        cnt2 = 0
        for k in range(10):
            if tf[k] and f[j][k]:
                cnt2 += 1
        cnt1 += p[j][cnt2]
    ans = max(ans, cnt1)
print(ans)

Submission status: Accepted

Solution code:
def bitcount(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f #8bitごと
    x = x + (x >> 8) #16bitごと
    x = x + (x >> 16) #32bitごと
    x = x + (x >> 32) #64bitごと = 全部の合計
    return x & 0x0000007f

def binary_to_int(x):
    temp = 0
    for i in range(len(str(x))):
        temp += 2**(len(str(x))-i-1) * int(str(x[i]))
    return temp

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

for i in range(1, 2**10):
    temp = 0
    for j in range(n):
        temp += p[j-1][bitcount(i & shops[j-1])]
    if i == 1:
        ans = temp
    elif temp > ans:
        ans = temp

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

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

ans = -10**10
for i in range(1,1<<10):
    c = [0] * n # 同時に店を開いている時間帯数
    for j in range(10):
        if i & (1<<j):
            for k,F in enumerate(f):
                if F[j]:
                    c[k] += 1
    profit = 0
    for j in range(n):
        profit += p[j][c[j]]
    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)]

li = []

for i in range(2**10):
    if i == 0:
        continue
    ans = 0
    co = [0]*n
    for j in range(10):
        if (i>>j &1)==1:
            for k in range(n):
                if f[k][j]==1:
                    co[k] +=1
    #print(i,bin(i),co)
    for l in range(n):
        ans += p[l][co[l]]
    li += [ans]
print(max(li))

Submission status: Accepted

Solution code:
from itertools import product

ans = -10**9 - 1

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

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

all_x = True
for ox in product((0, 1), repeat=10):
  if all_x:
    all_x = False
  else:
    temp = 0
    for n in range(N):
      cnt = 0
      for i, j in zip(F[n], ox):
        cnt += i*j
      temp += P[n][cnt]
    ans = max(ans, temp)

print(ans)

Submission status: Accepted

Solution code:
import sys, math
from functools import lru_cache
from collections import defaultdict
from decimal import Decimal
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    F = [list(mi()) for i in range(N)]
    P = [list(mi()) for i in range(N)]

    m = -math.inf

    for ptn in range(1, 2**10):
        r = 0
        for i in range(N):
            cnt = 0
            for j in range(10):
                if F[i][j] and (ptn>>j)&1:
                    cnt += 1
            r += P[i][cnt]
        m = max(m, r)

    print(m)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import math

input = sys.stdin.readline
N = int(input())
F = []
for _ in range(N):
    f = 0
    for i, k in enumerate(input().split()):
        f += pow(2, i) * int(k)
    F.append(f)

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


def cal_prof(bit_flg):
    ret = 0
    for i in range(N):
        f = bin(F[i] & bit_flg).count('1')
        ret += P[i][f]
    return ret

ans = -math.inf
for i in range(1, pow(2, 10)):
    ans = max(ans, cal_prof(i))
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**9)
for i in range(1, 2**10):
  l = [0] * N
  for j in range(10):
    if (i>>j) & 1:
      for k in range(N):
        if F[k][j] == 1:
          l[k] += 1
  tmp = 0
  for m in range(N):
    n = l[m]
    tmp += P[m][n]
  ans = max(tmp, 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 = -float('inf')
for i in range(1, 2**10):
    t = [1 if i & (1 << j) != 0 else 0 for j in range(10)]
    b = 0
    for j in range(N):
        c = 0
        for k in range(10):
            if t[k] == 1 and f[j][k] == 1:
                c += 1
        b += p[j][c]
    ans = max(ans, b)
print(ans)

Submission status: Accepted

Solution code:
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

n=int(input());ans=-inf
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())))

for bit in range(1,1<<10):
    L=[(bit>>i)&1 for i in range(10)]
    now=0
    for i in range(n):
        cnt=0
        for cc in range(10):
            if (F[i][cc]==1 and L[cc]==1) : cnt+=1
        now+=P[i][cnt]
    ans=max(ans,now)
print(ans)

Submission status: Accepted

Solution code:
import itertools

N = int(input())
M = 10
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 s in itertools.product([0, 1], repeat=M):
    if max(s) == 0:
        continue
    score = 0
    for i in range(N):
        cnt = 0
        for j in range(M):
            if s[j] and F[i][j]:
                cnt += 1
        score += P[i][cnt]
    ans = max(ans, score)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
f=[[] for i in range(n)]
for i in range(n):
    f[i]=list(map(int,input().split()))
p=[[] for i in range(n)]
for i in range(n):
    p[i]=list(map(int,input().split()))
ans=-10000000000
for i in range(1,1024):
    x=[]
    pro=0
    for j in range(10):
        x.append(i%2)
        i=i//2
    for j in range(n):
        c=0
        for k in range(10):
            if x[k]==f[j][k]==1:
                c+=1
        pro+=p[j][c]
    ans=max(ans,pro)
print(ans)

Submission status: Accepted

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

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

res = - 10 ** 11
for i in range(1, 1 << 10):
    tmp_res = 0
    for j in range(n):
        counter = 0
        for k in range(10):
            if i >> k & f[j][k]:
                counter += 1
        tmp_res += p[j][counter]
    res = max(res, tmp_res)

print(res)