Problem:


Score : 300 points

Problem Statement

Joisino is planning to open a shop in a shopping street.

Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods.

There are already N stores in the street, numbered 1 through N.

You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2.

Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}.

Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.

Constraints

1≤N≤100

0≤F_{i,j,k}≤1

For every integer i such that 1≤i≤N, there exists at least one pair (j,k) such that F_{i,j,k}=1.

-10^7≤P_{i,j}≤10^7

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
F_{1,1,1} F_{1,1,2} ... F_{1,5,1} F_{1,5,2}
:
F_{N,1,1} F_{N,1,2} ... F_{N,5,1} F_{N,5,2}
P_{1,0} ... P_{1,10}
:
P_{N,0} ... P_{N,10}

Output

Print the maximum possible profit of Joisino's shop.

Sample Input 1

1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2

Sample Output 1

8

If her shop is open only during the periods when Shop 1 is opened, the profit will be 8, which is the maximum possible profit.

Sample Input 2

2
1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1

Sample Output 2

-2

Note that a shop must be open during at least one period, and the profit may be negative.

Sample Input 3

3
1 1 1 1 1 1 0 0 1 1
0 1 0 1 1 1 1 0 1 0
1 0 1 1 0 1 0 1 0 1
-8 6 -2 -8 -8 4 8 7 -6 2 2
-9 2 0 1 7 -5 0 -2 -6 5 5
6 -6 7 -9 6 -5 8 0 -9 -7 -7

Sample Output 3

23



Sample input:
1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2


Sample output:
8

Submission status: Accepted

Solution code:
n = int(input())
F = []
P = []
for _ in range(n):
    F.append(list(map(int, input().split())))
for _ in range(n):
    P.append(list(map(int, input().split())))
ans = -1000000000
for pattern in range(1, 2 ** 10):
    _ans = 0
    for shop in range(n):
        match_cnt = 0
        for i in range(10):
            if F[shop][i] == 0:
                continue
            if (pattern >> i) & 1:
                match_cnt += 1
        _ans += P[shop][match_cnt]
    ans = max(ans, _ans)
print(ans)

Submission status: Accepted

Solution code:
def main():
    from sys import stdin
    def input():
        return stdin.readline().strip()

    def str_to_bool(i):
        if i == '0':
            return False
        else:
            return True

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

    # full search
    from itertools import product

    ans = -float('inf')
    flag = True
    for iterator in product([False, True], repeat=10):
        if flag:
            flag = False
            continue

        profit = 0
        for store_ind in range(n):
            num = 0
            for i in range(10):
                if iterator[i] and f[store_ind][i]:
                    num += 1
            profit += p[store_ind][num]
        
        if ans < profit:
            ans = profit

    print(ans)

main()

Submission status: Accepted

Solution code:
from itertools import product

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

ans = -(10 ** 10)
for bit in product([0, 1], repeat=10):
    if sum(bit) == 0:
        continue
    gain = 0
    for pi, fi in zip(p, f):
        tmp = sum(bitj & fij for bitj, fij in zip(bit, fi))
        gain += pi[tmp]
    ans = max(ans, gain)
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)]
ans = float('-inf')

for i in range(1, 2**10):
    ans = max(ans, sum(p[bin(i & f).count('1')] for f, p in zip(F, P)))
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
F = []
for _ in range(N):
    s = input().split()
    F.append(int("".join(s), base=2))
P = [list(map(int, input().split())) for _ in range(N)]
ans = -float("inf")
for bit in range(1, 2**10):
    gain = 0
    for i in range(N):
        ci = 0
        for j in range(10):
            if ((bit>>j) & 1) and ((F[i]>>j) & 1):
                ci += 1
        gain += P[i][ci]
    ans = max(ans, gain)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import heapq as hq
N = int(input())
F = np.array([[int(x) for x in input().split()] for _ in range(N)])
P = np.array([[int(x) for x in input().split()] for _ in range(N)])

Profit = []
for i in range(1,2**10): #営業時間帯についてbit全探索
    Open = np.array([int(x) for x in format(i, '010b')]).T #2進数を縦ベクトルに変換
    c = np.dot(F, Open) #店別に被る時間帯の個数をベクトルとして算出
    hq.heappush(Profit, -sum(P[i, c[i]] for i in range(N))) #-1倍した利益をProfitにpush。
print(-Profit[0]) #heapから最小値を取得

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

total = -10**9
for i in range(1,2**10):
    pgain = 0
    for f,p in zip(F,P):
        pgain += p[bin(f&i).count("1")]
    if total < pgain:
        total = pgain
        k = i
print(total)

Submission status: Accepted

Solution code:
import numpy as np
import heapq as hq
N = int(input())
F = np.array([[int(x) for x in input().split()] for _ in range(N)])
P = np.array([[int(x) for x in input().split()] for _ in range(N)])

Profit = []
for i in range(1,2**10): #bit全探索
    Open = np.array([int(x) for x in format(i, '010b')]) #2進数をベクトルに変換
    prf = 0
    for f, p in zip(F, P):
        cnt = np.dot(Open, f)
        prf += p[cnt]
    hq.heappush(Profit, -prf)
print(-Profit[0])

Submission status: Accepted

Solution code:
import numpy as np
import heapq as hq
N = int(input())
F = np.array([[int(x) for x in input().split()] for _ in range(N)])
P = np.array([[int(x) for x in input().split()] for _ in range(N)])

Profit = []
for i in range(1,2**10):
    Open = np.array([int(x) for x in format(i, '010b')])
    prf = 0
    for f, p in zip(F, P):
        cnt = np.dot(Open, f)
        prf += p[cnt]
    hq.heappush(Profit, -prf)
print(-Profit[0])

Submission status: Accepted

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

maxi = -10**10

for i in range(1,2**10):
    num = [0]*n
    for j in range(10):
        if ((i >> j) & 1):
            for k in range(n):
                num[k] += l[k][j]
    benefit = 0
    for m in range(n):
        benefit += p[m][num[m]]
    maxi = max(maxi,benefit)
print(maxi)

Submission status: Accepted

Solution code:
def dfs(s,N):
    if len(s)==10:
        if "1" in s:
            cal(s,N)
        return
    dfs(s+"0",N)
    dfs(s+"1",N)

def cal(s,N):
    p = 0
    for i in range(N):
        c=0
        for j in range(10):
            c+=F[i][j]*int(s[j])
        p+=P[i][c]
    profit.append(p)
    return

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

dfs("",N)
print(max(profit))

Submission status: Accepted

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

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

ans = -float("inf")

for j in range(1, 1024):
    ss = 0
    for i in range(N):
        b = format(j, "010b")
        bb = [0] * 10
        for k in range(10):
            bb[k] = F[i][k] * int(b[k])
        ss += P[i][sum(bb)]
    ans = max(ans, ss)

print(ans)

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=[]
for i in range(1,2**10):
    tmp=0
    for j in range(N):
        b=''.join(F[j])
        ct=0
        for k in range(10):
            if (i>>k)&int(b[k]):
                ct+=1
        tmp+=P[j][ct]
    ans.append(tmp)
print(max(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)]
import math
profit=-math.inf
for i in range(1,2**10):
  temp=0
  i=format(i,'b').rjust(10,'0')
  e=[]
  for j in range(10):
    if i[j]=='1':
      e.append(j)
  for k in range(N):
    count=0
    for l in range(len(e)):
      if F[k][e[l]]==1:
        count+=1
    temp+=P[k][count]
  profit=max(temp,profit)
print(profit)

Submission status: Accepted

Solution code:
def pad_zero(s, n):
	s = str(s)
	return ("0" * n + s)[-n:]

def main():
	N = int(input())
	F = [[int(f) for f in input().split(" ")] for i in range(N)]
	P = [[int(p) for p in input().split(" ")] for i in range(N)]

	total_profit = []
	for b in range(1, 2 ** 10):
		sale_bit = list(pad_zero(format(b, 'b'), 10))
		profit = 0
		for i in range(len(F)):
			f = F[i]
			p = P[i]
			profit += p[sum([fjk * int(s) for (fjk, s) in zip(f, sale_bit)])]
		total_profit.append(profit)
	print(max(total_profit))


main()

Submission status: Accepted

Solution code:
N=int(input())
J=10

F=[set() for _ in range(N)]
for i in range(N):
    G=list(map(int,input().split()))
    for j in range(J):
        if G[j]:
            F[i].add(j)

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

Ans=-float("inf")
for x in range(1,2**J):
    S=set()
    for t in range(J):
        if x%2:
            S.add(t)
        x>>=1

    Score=0
    for i in range(N):
        Score+=P[i][len(F[i]&S)]
    Ans=max(Ans,Score)
    assert 1

print(Ans)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

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

ans = -10**18
for S in range(1, 1<<10):
    res = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            if (1<<j) & S and F[i][j]:
                cnt += 1
        res += P[i][cnt]

    ans = max(ans, res)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
F = []
P = []
ans = -10**10
for i in range(N):
    F.append(list(map(int,input().split())))
for i in range(N):
    P.append(list(map(int,input().split())))
for i in range(1,2**10):
    profit = 0
    li = [0]*N
    for j in range(10):
        for k in range(N):
            if (i >> j & 1) and F[k][j]:
                li[k] += 1
    for k in range(N):
        profit += P[k][li[k]]
    ans = max(profit,ans)
print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


n = int(readline())
fs = [list(map(int, readline().split())) for _ in range(n)]
ps = [list(map(int, readline().split())) for _ in range(n)]

pat = list(itertools.product([0, 1], repeat=10))

ans = -10**9
for p in pat:
    if sum(list(p)) == 0:
        continue
    money = 0
    for i in range(n):
        cnt = 0
        for j in range(10):
            if fs[i][j] == 1 and p[j] == 1:
                cnt += 1
        money += ps[i][cnt]
    if ans < money:
        ans = max(ans, money)
print(ans)

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)]
ans = -float('inf')
for i in range(1, 2 ** 10):
  sum = 0
  for j in range(n):
    sum += p[j][bin(i & f[j]).count('1')]
  ans = max(ans, sum)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
f=[list(map(int,input().split())) for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(n)]
ans=-10**10
for status in range(1,2**10):
    c=[0]*n
    cur=0
    for t in range(10):
        for i in range(n):
            if (status>>t)&1==1 and f[i][t]==1:
                c[i]+=1
    
    for i in range(n):
        cur+=p[i][c[i]]
    
    ans=max(ans,cur)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

ans = -float('inf')
for i in range(1,1 << 10):
    g = [0] * N
    for j in range(10):
        if i >> j & 1:
            for k in range(N):
                g[k] += F[k][j]
    sub = 0
    for i in range(N):
        sub += P[i][g[i]]
    ans = max(ans, sub)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

ans = -10**18
for ci in range(1, 2**10):
    score = 0
    for cn in range(n):
        cnt = 0
        for cj in range(10):
            x = ci >> cj & 1
            if x and f[cn][cj]:
                cnt += 1
        score += p[cn][cnt]
    ans = max(ans, score)
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    n = int(input().strip())
    timetable = []
    profites = []
    ans = -(10**9)

    for _ in range(n):
        timetable.append([int(i) for i in input().strip().split()])
    for _ in range(n):
        profites.append([int(i) for i in input().strip().split()])

    for i in range(1, 2**10):
        on_service = [0] * 10
        overlaps = [0] * n
        for j in range(10):
            if i >> j & 1:
                on_service[j] = 1
                for k, table in enumerate(timetable):
                    if table[j] == 1:
                        overlaps[k] += 1
        _tmp = 0
        for m in range(n):
            ptr = overlaps[m]
            _tmp += profites[m][ptr]
        ans = max(ans, _tmp)
    print(ans)
    return


if __name__ == "__main__":
    main()

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

from itertools import product
bits_l=list(product([0,1], repeat=10))
bits_l.remove((0,0,0,0,0,0,0,0,0,0))

ans=-float("inf")
for bits in bits_l:
    tmp_ans=0
    for shop in range(n):
        tmp_cnt=0
        for i, bit in enumerate(bits):
            if bit==1 and f[shop][i]==1:
                tmp_cnt+=1
        tmp_ans+=p[shop][tmp_cnt]
    ans=max(ans, tmp_ans)

print(ans)

Submission status: Accepted

Solution code:
A=int(input())
shop_l=[list(map(int,input().split())) for i in range(A)]
shop_count_l=[list(map(int,input().split())) for i in range(A)]
ans=-1*10**10
for i in range(1,1024):
   tmp=0
   l=[0]*A
   for j in range(10):
      if (i>>j)&1:
         for k in range(A):
            if shop_l[k][j] == 1:
               l[k]+=1
   for i in range(A):
      tmp+=shop_count_l[i][l[i]]
   ans=max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    n = int(input())
    f = [list(map(int, input().split())) for _ in range(n)]
    p = [list(map(int, input().split())) for _ in range(n)]
    ans = -(10 ** 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)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

schejule_list = list(product([0, 1], repeat=10))
ans = - float("inf")
for schedule in schejule_list:
    if schedule == (0,0,0,0,0,0,0,0,0,0):
        continue
    res = 0
    for i in range(n):
        kaburi = 0
        for j in range(10):
            kaburi += f[i][j] * schedule[j]
        res += p[i][kaburi]
    ans = max(ans, res)
print(ans)

Submission status: Accepted

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

schejule_list = set(product([0, 1], repeat=10))
ans = - float("inf")
for schedule in schejule_list:
    if schedule == (0, 0, 0, 0, 0, 0, 0, 0, 0, 0):
        continue
    res = 0
    for i in range(n):
        kaburi = 0
        for j in range(10):
            kaburi += f[i][j] * schedule[j]
        res += p[i][kaburi]
    ans = max(ans, res)
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:
import sys
from heapq import heappush, heappop
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())


def main():
    n = ii()
    F = []
    P = []
    for _ in range(n):
        F.append(li())
    for _ in range(n):
        P.append(li())
    
    inf = 10 ** 18
    ans = -inf
    for i in range(1, 1<<10):
        c = [0]*(n)
        tmp = 0
        for j in range(10):
            if (i>>j)&1:
                for k in range(n):
                    c[k] += F[k][j]
        for k in range(n):
            tmp += P[k][c[k]]
        ans = max(ans, tmp)
    print(ans)
            
            
        
    




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def ForBaseConvert(Roop,MaxD,Base):
    if all(type(TT) is int for TT in [Roop,MaxD,Base]):
        if Base>=2 and MaxD>=1:
            ConvertN = []
            while Roop>0:
                ConvertN.append(Roop%Base)
                Roop = Roop//Base

            BaseConv = [0]*(MaxD-len(ConvertN))+ConvertN[::-1]
            BaseSInd = [[] for TB in range(0,Base)]
            for TB in range(0,Base):
                BaseSInd[TB] = [SInd for SInd,SNum in enumerate(BaseConv) if SNum==TB]
            return BaseConv,BaseSInd
        else:
            return []
    else:
        return []
      
N = int(input())
F = [[] for TF in range(0,N)]
for TF in range(0,N):
    F[TF] = [int(T) for T in input().split()]
P = [[] for TP in range(0,N)]
for TP in range(0,N):
    P[TP] = [int(T) for T in input().split()]
    
MAXB = -10**9
for TB in range(1,2**10):
    BaseConv,BaseSInd = ForBaseConvert(TB,10,2)
    Benefit = 0
    for TN in range(0,N):        
        Count = sum(1 if F[TN][TT]==1 else 0 for TT in BaseSInd[1])
        Benefit += P[TN][Count]
    if MAXB<Benefit:
        MAXB = Benefit
print(MAXB)

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)*(-1)
for i in range(1,2**10):
    cnt=[0]*n
    for j in range(10):
        if i>>j &1:
            for x in range(n):
                if F[x][j]==1:
                    cnt[x]+=1
    tmp=0
    for k in range(n):
        tmp+=P[k][cnt[k]]
    ans=max(ans,tmp)

print(ans)

Submission status: Accepted

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

ans = -10**12
from itertools import product
for i in range(1, 2**10):
    pattern = [(i>>j)&1 for j in range(10)]
    rieki = 0
    for ff, pp in zip(F, P):
        count = sum([f and p for f, p in zip(ff, pattern)])
        rieki += pp[count]

    ans = max(ans, rieki)
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

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

MAX=-10**12
for p in product(range(2),repeat=10):
  if p==(0,)*10:continue
  SUM=0
  for i in range(N):
    count=0
    for j in range(10):
      if p[j]==1 and F[i][j]==1:
        count+=1
    SUM += P[i][count]
  MAX = max(MAX,SUM)
print(MAX)

Submission status: Accepted

Solution code:
n=int(input())
import numpy as np
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())))
x=np.asarray(f)
mx=-10**9
for i in range(1,2**10):
    y=np.asarray([int(x) for x in list(format(i,'010b'))])
    z=x*y
    can=np.sum(z,axis=1)
    c=0
    for j in range(n):
        c += p[j][can[j]]
    mx=max(c,mx)
print(mx)

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

import itertools

ans = -10**10
for I in itertools.product([0,1],repeat=10):
    if sum(list(I))==0:
        continue
    
    TMP = 0
    for i in range(N):
        tmp = 0
        for j in range(10):
            if F[i][j]==1 and I[j]==1:
                tmp+=1
        TMP += P[i][tmp]
    
    ans = max(ans,TMP)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
F = [int(''.join(list(input().split())), 2) 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):
    res = 0
    for k in range(N):
        p = i & F[k]
        cnt = 0
        for j in range(10):
            if (p >> j) & 1:
                cnt += 1
        res += P[k][cnt]
    ans = max(ans, res)

print(ans)

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    F = [LI() for _ in range(N)]
    P = [LI() for _ in range(N)]

    ans = -INF
    for i in range(1, 2 ** 10):
        tmp = 0
        for j in range(N):
            cnt = 0
            for k in range(10):
                if i >> k & 1:
                    cnt += F[j][k]
            tmp += P[j][cnt]
        ans = max(tmp, ans)

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
schedules = [list(map(int, input().split())) for _ in range(N)]
prices = [list(map(int, input().split())) for _ in range(N)]
# print(schedules)
# print(prices)
ans = -1 * float('inf')
for i in range(1, 1 << 10):
    my_schedule = list(map(int, bin(i)[2:].zfill(10)))
    score = 0
    for j, schedule in enumerate(schedules):
        count = 0
        for k in range(10):
            if my_schedule[k] == schedule[k] and schedule[k] == 1:
                count += 1
        score += prices[j][count]
    ans = max(ans, score)
print(ans)

Submission status: Accepted

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
f = []
for i in range(n):
    f.append(LIST())
p = []
for i in range(n):
    p.append(LIST())

ans = -inf
for x in product([0, 1], repeat=10):
    if sum(x) != 0:
        tmp = 0
        for j in range(n):
            count = 0
            for k in range(10):
                count += f[j][k]*x[k]
            tmp += p[j][count]
        ans = max(ans, tmp)
print(ans)

Submission status: Accepted

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

bh=[0]*n
c=[0]*n
for i,s in enumerate(f):
  for j,h in enumerate(s):
    bh[i]|=h<<j

maxp=-float('inf')
for mbh in range(1,2**10):
  for i in range(n):
    intsect=mbh&bh[i]
    c[i]=sum(intsect>>k&1 for k in range(10))
  maxp=max(maxp,sum(p[i][c[i]] for i in range(n)))
print(maxp)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
import heapq

sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret

def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid

    def pos(self, x, y):
        return y * (self.w + 2) + x + 1

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]

        ans = 0
        for i in range(1, self.h + 1):
            for j in range(1, self.w + 1):
                pass # ここから何か書いてね
def bc(bi):
    # bit-count
    ret = 0
    while(bi > 0):
        if bi & 1 == 1:
            ret += 1
        bi //= 2
    return ret

def judge(bi, fnums, pnums):
    ret = 0
    for i, fnum in enumerate(fnums):
        tmp = bi & fnum

        ret += pnums[i][bc(tmp)]
    # print(ret, bi)
    return ret

def solve():
    n = getN()
    fnums = []
    for i in range(n):
        fnums.append(getList())
    fnums = [int("".join(list(map(str, fnum))), 2) for fnum in fnums]
    # print(fnums)
    pnums = []
    for i in range(n):
        pnums.append(getList())
    ans = -INF
    for bi in range(1, 1 << 10):
        ans = max(ans, judge(bi, fnums, pnums))

    print(ans)

def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Submission status: Accepted

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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**12
for i in range(1, 2**10):
    tres = 0
    cnts = [0]*N
    for j in range(10):
        bo = (i>>j) & 1
        for k in range(N):
            cnts[k] += F[k][j] & bo
    for k in range(N):
        tres += P[k][cnts[k]] 
    if res < tres:
        res = tres
print(res)

Submission status: Accepted

Solution code:
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def dec(digits):
    answer = 0
    for d in digits:
        answer = (answer<<1) + d
    return answer

def bitcount(n):
    answer = 0
    while n != 0:
        answer += n&1
        n >>= 1
    return answer

def solve():
    N = read_int()
    F = []
    P = []
    for _ in range(N):
        F.append(dec(read_ints()))
    for _ in range(N):
        P.append(read_ints())
    max_profit = -math.inf
    for day in range(1, 1<<10):
        profit = 0
        for i in range(N):
            profit += P[i][bitcount(F[i]&day)]
        max_profit = max(max_profit, profit)
    return max_profit


if __name__ == '__main__':
    print(solve())

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

Submission status: Accepted

Solution code:
import sys

N = int(input())
Bs = 2**10

Fs = []
Ps = []
l1 = []
for _ in range(N):
  s = int(input().replace(' ', ''), 2)
  Fs.append(s)
for _ in range(N):
  Ps.append(list(map(int, input().split())))

rlt = -sys.maxsize
for b in range(1,Bs):
  tmp = 0
  for i in range(N):
    t = b&Fs[i]
    t = bin(t)[2:]
    c = t.count('1')
    tmp += Ps[i][c]
  rlt = max(rlt, tmp)
  
print(rlt)