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:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    F = [[[0 for _ in range(2)] for _ in range(5)] for _ in range(N)]
    for i in range(N):
        tmp = inputList()
        for j,val in enumerate(tmp):
            ind = j // 2
            if j % 2 == 0:
                F[i][ind][0] = val
            else:
                F[i][ind][1] = val
                
    P = []
    for i in range(N):
        tmp = inputList()
        P.append(tmp)
        
    ans = -100000000000000000000000000
    for i in range(1, 2**10):
        ans_tmp = [0 for _ in range(N)]
        for j in [1,2,2**2,2**3,2**4,2**5,2**6,2**7,2**8,2**9]:
            tmp = j & i
            ind = 0
            hi = 0
            
            if tmp == 0:
                ind = -1
                hi = -1
            elif tmp == 1:
                ind = 0
                hi = 0
            elif tmp == 2:
                ind = 0
                hi = 1
            elif tmp == 4:
                ind = 1
                hi = 0
            elif tmp == 8:
                ind = 1
                hi = 1
            elif tmp == 16:
                ind = 2
                hi = 0
            elif tmp == 32:
                ind = 2
                hi = 1
            elif tmp == 64:
                ind = 3
                hi = 0
            elif tmp == 128:
                ind = 3
                hi = 1
            elif tmp == 256:
                ind = 4
                hi = 0
            elif tmp == 512:
                ind = 4
                hi = 1
                
            if ind != -1:
                for k in range(N):
                    tmp2 = F[k][ind][hi]
                    #if k == 0:
                        #print("{} {} {}".format(k,ind,hi))
                    #if i == 683:
                        #print("{} {} {}".format(k,ind,hi))
                    if tmp2 == 1:
                        ans_tmp[k] += 1
                        
        a_tmp = 0
        for j in range(N):
            a_tmp += P[j][ans_tmp[j]]
        if ans < a_tmp:
            ans = a_tmp
        
    print(ans)
            	
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import sys

def main():
	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 = -sys.maxsize
	for x10 in range(1,2**10):
		x2 = base_10_to_n(x10,2)
		for _ in range(10-len(x2)):	
			x2 = '0' + x2
		benefit = 0
		for j in range(n):
			count = 0
			for k in range(10):
				if(f[j][k] == 1 and x2[k] == '1'):
					count+=f[j][k]
			benefit+=p[j][count]
		if(ans<benefit): ans = benefit
	print(ans)

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

Submission status: Accepted

Solution code:
N = int(input())
F = []
for n in range(N):
  F.append([k for k, x in enumerate(input().split()) if x=="1"])
P = []
for n in range(N):
  P.append([int(p) for p in input().split()])

PROFIT = []
for i in range(1, 2**10):
  i = format(i, "b")
  if len(i) < 10:
    i = "0"*(10-len(i)) + i
  OPEN_joisino = [k for k, x in enumerate(i) if x=="1"]
  profit = 0
  for n in range(N):
    together_time = 0
    for t in OPEN_joisino:
      if t in F[n]:
        together_time += 1
    profit += P[n][together_time]
  PROFIT.append(profit)
ans = max(PROFIT)
print(ans)

Submission status: Accepted

Solution code:

N = input()
N = int(N)
Fs =  [list(map(int,input().split(" "))) for _ in range(N)]
Ps =  [list(map(int,input().split(" "))) for _ in range(N)]
ans = -(10**10)
for flag in range(1,2 ** 10): #開店スケジュールに対応
    temp = 0
    for shop in range(N):
        op = 0

        for i in range(10): #曜日に対応
            if flag & (1 << i):
                c = 1#ある曜日にやっているか
            else:
                c = 0
            if Fs[shop][i] * c == 1:
                op += 1

        temp +=Ps[shop][op]
    if temp > ans:
        ans =temp
print(ans)

Submission status: Accepted

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

ans = -10 ** 12
for i in range(1, 1024):
    chk = list(str(bin(i+1024)))[3:]
    profit = 0
    for n in range(N):
        total = 0
        for j, c in enumerate(chk):
            if c == "1":
                total += F[n][j]
        profit += P[n][total]
    if profit > ans:
        ans = profit

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

Submission status: Accepted

Solution code:
N = int(input())
F = [[int(f) for f in input().split()] for _ in range(N)]
P = [[int(p) for p in input().split()] for _ in range(N)]

saidai_rieki = -1*(10**10)
for i in range(1,2**10):
    C = [0]*N
    for time in range(10):
        if (i>>time)%2==1:
            for j in range(N):
                C[j] += F[j][time]    
    saidai_rieki = max(saidai_rieki,sum([P[j][C[j]] for j in range(N)]))
print(saidai_rieki)

Submission status: Accepted

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

ans = -(10 ** 9)
for i in range(1, 2 ** 10):
    tmp = 0
    for j in range(N):
        f = int('0b' + ''.join(F[j]), 0)
        tmp += P[j][bin(i & f).count('1')]
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

# 各曜日時間帯に開くか開かないかは2**10=1024通りしかないので
# O(N*2**10) = O(10**5)で間に合う
# 長さ10の配列に0 or 1を格納するbit全探索を行う。
# F[i][j]: 店i, jは曜日と時間帯を表す0~9

n = 10
max_profit = - float("inf")
for bit in range(1, 1<<n):  # 2**10まで2進数で(1つ以上の時間帯で営業しないといけないから000000000を除くため、1スタート)
    profit = 0
    for i in range(N):  # 店の数
        count = 0
        for j in range(n):  # bit（10桁）のどこに1があるか調べる
            if F[i][j] == 1 and (bit>>j) & 1:  # 右シフトしたbitの最後の桁が1ならTrue
                    # 10回シフトして最後の桁が1か調べる == bitのj桁目に1があればTrue
                count += 1
        profit += P[i][count]
    max_profit = max(max_profit, profit)

print(max_profit)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

# 各曜日時間帯に開くか開かないかは2**10=1024通りしかないので
# O(N*2**10) = O(10**5)で間に合う
# 長さ10の配列に0 or 1を格納するbit全探索を行う。
# F[i][j]: 店i, jは曜日と時間帯を表す0~9

n = 10
max_profit = - float("inf")
for bit in range(1, 1<<n):  # 2**10まで2進数で(1つ以上の時間帯で営業しないといけないから000000000を除くため、1スタート)
    profit = 0
    for i in range(N):  # 店の数
        count = 0
        for j in range(n):  # bit（10桁）のどこに1があるか調べる
            if F[i][j] == 1:
                if (bit>>j) & 1:  # 右シフトしたbitの最後の桁が1ならTrue
                    # 10回シフトして最後の桁が1か調べる == bitのj桁目に1があればTrue
                    count += 1
        profit += P[i][count]
    max_profit = max(max_profit, profit)

print(max_profit)

Submission status: Accepted

Solution code:
import numpy as np

# 店の数を入力する
N = int(input())
# 店の営業時間の情報を入力する
F = np.zeros((N, 10), dtype = int)
for i in range(N):
    F_i = list(map(int, input().split()))
    F[i] = [val for j, val in enumerate(F_i)]
# 各店と同時に営業したときの利益を入力する
P = np.zeros((N, 11), dtype = int)
for i in range(N):
    P[i] = list(map(int, input().split()))
# joisinoの開店パターン行列を作成する
matrix_pattern = np.zeros((2**10 - 1, 10), dtype = int)
for x in range(10):
    for y in range(0, 2**(10 - x), 2):
        matrix_pattern[(2**x * y):(2**x * (y + 1)), x] = 1
# 開店パターンごとの利益を格納するリストを作成する
list_profit = []
# joisinoの開店パターンごとに利益を計算
for pattern in matrix_pattern:
    # joisinoの店の利益を初期化する
    profit = 0
    # 店ごとに繰り返す
    for i in range(N):
        # 同時に営業している時間帯の個数（c_i）を計算する
        c_i = sum(F[i] * pattern)
        # joisinoの店の利益を更新する
        profit += P[i, c_i]
    list_profit.append(profit)
# 利益の最大値を出力する
print(max(list_profit))

Submission status: Accepted

Solution code:
n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
res = -10**10
for i in range(1, 1<<10):
    count = [0 for _ in range(n)]
    for j in range(10):
        for k in range(n):
            if (i>>j)&1 == 1 and f[k][10-j-1] == 1:
                count[k] += 1
    total = 0
    for k in range(n):
        total += p[k][count[k]]
    res = max(res, total)
print(res)

Submission status: Accepted

Solution code:
def inner_prod(vec_a, vec_b):
    ans = 0
    for a, b in zip(vec_a, vec_b):
        ans += a * b
    return ans


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, 1024):
    flags = [(i & (2 ** b)) // (2 ** b) for b in range(10)]
    benefit = 0
    for j, f in enumerate(F):
        benefit += P[j][inner_prod(flags, f)]
    ans = max(ans, benefit)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
f = [int(input().replace(' ',''),2) for _ in range(N)]
p = [list(map(int,input().split())) for _ in range(N)]
g = -9999999999
for i in range(1,1024):
    gg = 0
    for j in range(N):
        s = (format(i & f[j],'b').zfill(10))
        c = s.count('1')
        gg += p[j][c]
    g = max(g,gg)
print(g)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC80 C

from operator import itemgetter
import collections

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

ma = -float('inf')
for i in range(1,2**10):
    b = [0]*10
    s = 0
    sum = 0
    for j in range(10):
        if (i>>j) & 1:
            b[j] = 1
    for j in range(n):
        for k in range(10):
            if f[j][k] & b[k]:
                s += 1
        sum += p[j][s]
        s = 0
    ma = max(ma,sum)
print(ma)

Submission status: Accepted

Solution code:
def larger(x, y):
	if x > y:
		return x
	return y

def openshop(n):
	lst = []
	m = n
	for i in range(0, 10):
		lst.append(m%2)
		m //= 2
	return lst

N = int(input())
F = []
for i in range(0, N):
	F.append(list(map(int, input().split())))
P = []
for i in range(0, N):
	P.append(list(map(int, input().split())))
max = -5000000000000000
for i in range(1, 1024):
	joisino = openshop(i)
	opencounter = []
	for j in range(0, N):
		opencounter.append(0)
	for j in range(0, 10):
		if joisino[j] == 1:
			for k in range(0, N):
				opencounter[k] += F[k][j]
	sum = 0
	for j in range(0, N):
		sum += P[j][opencounter[j]]
	max = larger(max, sum)
print(max)

Submission status: Accepted

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

ans = - 10**10
for i in range(1, 1<<10):
    tmp_ans = 0
    for j in range(n):
        c = 0
        for k in range(10):
            if f[j][k] == 1 and (i >> k) & 1 == 1:
                c += 1
        tmp_ans += p[j][c]
    ans = max(ans, tmp_ans)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
f=[]
p=[]
for i in range(n):
    q=[int(j) for j in input().split()]
    f.append(q)
for i in range(n):
    q=[int(j) for j in input().split()]
    p.append(q)

def base(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out.rjust(10,'0')
ans=-10**100
for i in range(1,1024):
    i=base(i,2)
    res=0
    for j in range(n):
        c=0
        for k in range(10):
            if f[j][k]==1 and int(i[k])==1:
                c+=1
        res+=p[j][c]
    ans=max(ans,res)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
lst_F = [list(map(int, input().split())) for _ in range(N)]
lst_P = [list(map(int, input().split())) for _ in range(N)]
n_timetable = 10
lst_joisino = [None] * n_timetable


def score(src, F, P):
    cnt = 0
    for i, j in zip(src, F):
        if i == j == 1:
            cnt += 1
    return P[cnt]


def dfs(pos):
    if pos == n_timetable:
        ret = 0
        for i in range(N):
            if lst_joisino == [0] * n_timetable:
                return -float("INF")
            p = score(lst_joisino, lst_F[i], lst_P[i])
            ret += p
        return ret
    lst_joisino[pos] = 0
    ret0 = dfs(pos + 1)
    lst_joisino[pos] = 1
    ret1 = dfs(pos + 1)
    return max(ret0, ret1)


print(dfs(0))

Submission status: Accepted

Solution code:
N=int(input())
F=[int(input().replace(" ",""),2) for _ in [0]*N]
P=[list(map(int,input().split())) for _ in [0]*N]
print(max([sum([P[j][bin(i&F[j]).count("1")] for j in range(N)]) for i in range(1,1024)]))

Submission status: Accepted

Solution code:
n = int(input())
open_list = [ [ int(v) for v in  input().split() ] for i in range(n)]
profit_list = [ [ int(v) for v in  input().split() ] for i in range(n)]

ans = -10**9
for i in range(1,1024):
    total_profit = 0
    shop = [ int(v) for v in bin(i)[2:].zfill(10) ]
    for j in range(n):
        total_profit += profit_list[j][sum([shop[k] & open_list[j][k] for k in range(10)])]
    ans = max(ans,total_profit)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
F=[[] for i in range(10)]
for i in range(n):
    for j,f in enumerate(list(map(int,input().split()))):
        if f:
            F[j].append(i)
P=[list(map(int,input().split())) for i in range(n)]
ans=-float("inf")
for i in range(1,1024):
    l=[0]*n
    for j in range(10):
        if i>>j&1:
            for k in F[j]:
                l[k]+=1
    t=0
    for j,k in enumerate(l):
        t+=P[j][k]
    ans=max(ans,t)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
F=[]
for i in range(n):
    sub_list=list(map(int,input().split()))
    F.append(sub_list)
P=[]
for i in range(n):
    sub_list=list(map(int,input().split()))
    P.append(sub_list)
Ans=-10**10
for i in range(1,1024):
    i_list=[]
    for j in range(10):
        i_list.append((i>>j)&1)
    ans=0
    for j in range(n):
        count=0
        for k in range(10):
            count+=F[j][k]*i_list[k]
        ans+=P[j][count]
    Ans=max(Ans,ans)
print(Ans)

Submission status: Accepted

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

ans = 0
for i in range(1, 2**10):
    pat = format(i, "010b")
    score = 0
    for j in range(n):
        cnt = 0
        for k in range(10):
            if pat[k]=="1" and f[j][k] == 1:
                cnt += 1
        score += p[j][cnt]
    if i == 1:
        ans = score
    ans = max(score, ans)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
F = list(list(map(int,input().split()))for i in range(N))
P = list(list(map(int,input().split()))for i in range(N))
ans = -float('inf')
for i in range(1023):
    b = bin(1024+i+1)[3:]
    pp = [0]*N
    for j in range(N):
        for k in range(10):
            if F[j][k] == 1 and b[k] == "1":
                pp[j] += 1
    hoge = 0
    for j in range(N):
        hoge += P[j][pp[j]] 
    ans = max(ans,hoge)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
f=[[int(i) for i in input().split()] for _ in range(n)]
p=[[int(i) for i in input().split()] for _ in range(n)]
ans=-10000000000000
All=[[] for _ in range(2**10)]
count=0
for bit in range(1<<10):
    pattarn = []
    for j in range(10):
        if (bit & (1<<j)):
            pattarn.append(j)
    All[count]=pattarn
    count+=1

for i in range(len(All)):
    All[i]=tuple(All[i])
All=sorted(list(set(All)),key=len)[1:]
for i in All:
    result=0
    for j in range(n):
        s=0
        for num in i:
            s+=f[j][num]
        res=p[j][s]
        result+=res
    ans=max(ans,result)
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)]

# print(f)
# print(p)
ans=-2**(31-1)

for i in range(1,2**10):
    list=[0]*n
    earn=0
    for j in range(10):
        for k in range(n):
            if i&(1<<j) and f[k][j]==1:
                list[k]+=1
    
    for k in range(n):
        earn+=p[k][list[k]]
    
    ans=max(ans, earn)
print(ans)

Submission status: Accepted

Solution code:

N = int(input())

F = []

for i in range(N):

    f = list(map(int,input().split()))

    F.append( [f[0],f[1] ,f[2],f[3] , f[4],f[5] , f[6],f[7] , f[8],f[9] ] )

P = []

for i in range(N):

    p = list(map(int,input().split()))

    P.append(p)

ans = -N * (10 ** 7)

for i in range(2 ** 10):
    
    nt = format(i,"b")
    nt = nt.zfill(10)

    #print (nt)

    now = 0

    for j in range(N):

        both = 0
        for k in range(10):

            if F[j][k] == 1 and nt[k] == "1":
                both += 1

        now += P[j][both]
        #print (j,both,now)

    if i != 0:
        ans = max(now,ans)

print (ans)

Submission status: Accepted

Solution code:
n = int(input())
f = [int(input().replace(' ',''),2) for _ in range(n)]
p = [list(map(int,input().split())) for _ in range(n)]
prof = - 10 ** 10
for i in range(1,1 <<10):
	prof1 = 0
	for j,time in enumerate(f):
		prof1 += p[j][bin(i & time).count('1')]
	prof = max(prof,prof1)
print(prof)

Submission status: Accepted

Solution code:
n = int(input())
f = [int(input().replace(' ',''),2) for i in range(n)]
p = [list(map(int,input().split())) for i in range(n)]
prof = - 10 ** 10
for i in range(1,1 <<10):
	prof1 = 0
	for j,time in enumerate(f):
		prof1 += p[j][bin(i & time).count('1')]
	prof = max(prof,prof1)
print(prof)

Submission status: Accepted

Solution code:
n = int(input())
f = [int(input().replace(' ',''),2) for i in range(n)]
p = [list(map(int,input().split())) for i in range(n)]
prof = - 10 ** 10
for i in range(1,1 <<10):
	prof1 = 0
	for j,time in enumerate(f):
		same = bin(i & time).count('1')
		prof1 += p[j][same]
	prof = max(prof,prof1)
print(prof)

Submission status: Accepted

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

ans=-10**10
for i in range(1,1<<10):
    prof=0
    for j,f in enumerate(F):
        prof+=P[j][bin(i&f).count("1")]
    ans=max(ans,prof)

print(ans)

Submission status: Accepted

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

for i in range(1,2**10):
    bit = format(i,"010b")
    C = [0]*(N)
    temp = 0
    for b in range(10):
        if bit[b] == "1":
            for j in range(N):
                if F[j][b] == 1:
                    C[j] += 1
    for p,c in zip(P,C):
        temp += p[c]
    if temp > ans:
        ans = temp
print(ans)

Submission status: Accepted

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

ans=-10**10
for i in range(1,1<<10):
    prof=0
    for j,f in enumerate(F):
        prof+=P[j][bin(i&f).count("1")]
    ans=max(ans,prof)

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())))
ans = -(10**10)
for i in range(1,2**10):
    x=0
    binary=format(i,"010b")
    for j in range(n):
        cnt=0
        for k in range(10):
            if binary[k]=="1" and f[j][k]==1:
                cnt+=1
        x += p[j][cnt]
    ans = max(ans,x)
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)]

result = -10**9
for b in range(1, 1 << 10):
    c = [0 for _ in range(N)]
    for t in range(10):
        if (b & (1 << t)) != 0:
            # Joisino's shop is open
            for i in range(N):
                if F[i][t] == 1:
                    c[i] += 1
    profit = 0
    for i in range(N):
        profit += P[i][c[i]]
    result = max(result, profit)
print(result)

Submission status: Accepted

Solution code:
INF = float("inf")
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
opens = []
for i in range(N):
    opens.append(nl())
profits = []
for i in range(N):
    profits.append(nl())

max_profit = -INF

import itertools
for p in itertools.product([0, 1], repeat=10):
    if all([i == 0 for i in p]):
        continue
    profit = 0
    for i in range(N):
        count = 0
        for j in range(10):
            count += opens[i][j] * p[j]
        profit += profits[i][count]
    if profit > max_profit:
        max_profit = profit

print(max_profit)

Submission status: Accepted

Solution code:
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 = -1*10**9
for i in range(1,2**10):
    ls = []
    for j in range(10):
        if (i>>j)&1:
            ls.append(1)
        else:
            ls.append(0)
    cnt = []
    for k in range(n):
        cn = 0
        for l in range(10):
            if ls[l]==f[k][l]==1:
                cn+=1
            else:
                pass
        cnt.append(cn)
    can =0    
    for m in range(n):
        can += p[m][cnt[m]]
    
    ans = max(ans,can)

print(ans)

Submission status: Accepted

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

def solve(N, F, P):
    max_prof = -1 * float('inf')
    for seq in itertools.product([True,False], repeat = 10):
        if not any(seq):
            continue

        prof = 0
        for f,p in zip(F,P):
            prof += p[sum(itertools.compress(f, seq))]
        max_prof = max(prof,max_prof)
    print(max_prof)


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    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())))

    solve(N, F, P)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
F,P,F0=[],[],[]
ans=-10**9
for b in range(1,2**10):
    F0.append(format(b,'010b'))
for _ in range(N):
    F.append(list(input().split()))
for _ in range(N):
    P.append(list(map(int,input().split())))

for c in F0:
    benefit=0
    for i in range(N):
        counter=0
        for j in range(10):
            if c[j]=="1" and F[i][j]=="1":counter+=1
        benefit+=P[i][counter]
    ans=max(ans,benefit)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
flist = []
for _ in range(n):
    flist.append([int(f) for f in input().split()])

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

def commonSum(a_l, b_l):
    """共通要素を返す"""
    cnt = 0
    for a, b in zip(a_l, b_l):
        if a == b and a == 1:
            cnt += 1
    return cnt

# 初期値
profit = -10**15
for open in range(1, 2**10):
    openlist = [int(i) for i in format(open, 'b').zfill(10)]

    # 各店との利益を求める
    prof = 0
    for i in range(n):
        common = commonSum(flist[i], openlist)
        prof += plist[i][common]
    if profit < prof:
      profit = prof
print(profit)

Submission status: Accepted

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

A=[]
for i in range(1,2**10):
    ans=0
    for s in range(n):
        count=0
        for j in range(10):
            if ((i>>j)&1) and store[s][j]==1:
                count+=1
        ans+=score[s][count]
    A.append(ans)
print(max(A))

Submission status: Accepted

Solution code:
import numpy as np
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)]

import itertools
answer = -(10 ** 18)
for a in itertools.product([0,1], repeat = 10):
  if sum(a) == 0:
    continue
  profit = 0
  for shop in range(N):
    profit += P[shop][sum(a[i]*F[shop][i] for i in range(10))]
  if answer < profit:
    answer = profit

print(answer)

Submission status: Accepted

Solution code:
n = int(input())
f_matrix = [[0]*10]*n
p_matrix = [[0]*11]*n
f_matrix = [[int(i) for i in input().split()] for _ in range(n)]
p_matrix = [[int(i) for i in input().split()] for _ in range(n)]

ans = -10**20
for i in range(1, 2**10):
  tmp = 0
  for j in range(n):
    c = 0
    for k in range(10):
      if i>>k&1 and f_matrix[j][k] is 1:
        c += 1
    tmp += p_matrix[j][c]
  ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np
INF = 10000000000
M = 10


def main():
    n = int(input())
    fveclist = [np.array([int(e) for e in input().split()]) for _ in range(n)]
    plist = [[int(e) for e in input().split()] for _ in range(n)]
    ans = -INF
    for b in range(1, pow(2, M)):
        joisino = np.array([b >> i & 1 for i in range(M)])
        subans = 0
        for i in range(n):
            subans += plist[i][(fveclist[i] * joisino).sum()]
        ans = max(ans, subans)
    print(ans)


main()

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)]
print(max([(sum([P[shop][sum([i*j for i,j in zip([i>>k & 1 for k in range(10)],F[shop])])] for shop in range(N)])) 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)]
R=[]
for i in range(1,1024):
    opentime = [i>>k & 1 for k in range(10)]
    R.append(sum([P[shop][sum([i*j for i,j in zip(opentime,F[shop])])] for shop in range(N)]))
print(max(R))