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

Submission status: Accepted

Solution code:
N = int(input())

# Fのデータを取得
list_f = []
for n in range(N):
  list_f.append(list(map(int,input().split())))

# Pのデータを取得
list_p = []
for n in range(N):
  list_p.append(list(map(int,input().split())))

'''考え方
各開店パターン毎に「その時の利益」を計算する
'''

from itertools import product

list_01 = [0,1]
array_prd = list(product(list_01,repeat=10))
max_prof = - 10 ** 18

for i in range(1024):
  if array_prd[i] == (0,0,0,0,0,0,0,0,0,0):
    continue
    
  tmp = 0
  
  for j in range(N):
    cnt_open = sum([ary * int(open_or_close) for ary,open_or_close in zip(array_prd[i],list_f[j])])
    tmp += list_p[j][cnt_open]
  
  if tmp > max_prof:
    max_prof = tmp

print(max_prof)

Submission status: Accepted

Solution code:
from itertools import product

n = int(input())
F = [tuple(map(int,input().split())) for _ in range(n)]
P = [tuple(map(int,input().split())) for _ in range(n)]
ans = -float("inf")

for ptn in product((0, 1), repeat=10):
    if ptn == (0, 0, 0, 0, 0, 0, 0, 0, 0, 0):
        continue
    tmp = 0
    for i in range(n):
        now = sum([ptn[x] * F[i][x] for x in range(10)])
        tmp += P[i][now]
    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)]
def dfs(cur):
    if len(cur)==10:
        ans = 0
        if sum(cur)==0:
            return -(10**9)
        for i in range(n):
            match=0
            for j in range(10):
                if cur[j]==f[i][j]==1:
                    match+=1
            ans+=p[i][match]
        return ans
    ret1 = dfs(cur+[0])
    ret2 = dfs(cur+[1])
    return max(ret1,ret2)
print(dfs([]))

Submission status: Accepted

Solution code:
import itertools
n = int(input())
p,f = [],[]

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

a = [0,1]
ans = -10**15
for v in itertools.product(a,repeat = 10):
    if sum(v) != 0:
        s = []
        for a in range(n):
            k = 0
            for b in range(10):
                if f[a][b] == v[b] and v[b] == 1:
                    k += 1
            s.append(k)

        x = 0
        for a in range(n):
            x += p[a][s[a]]
        if x > ans:
            #print(v,s,x)
            ans = x

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
F=np.array([list(map(int,input().split(' '))) for i in range(N)])
#row:shop, col:openpattern

P=np.array([list(map(int,input().split(' '))) for i in range(N)])

openptn=np.array([[int(s) for s in list('{0:010b}'.format(i))] for i in range(1,2**10)])
#row:openpatterns, col:openpattern

dualopenfreq=np.array([np.sum(ptn*F, axis=1) for ptn in openptn])
#row:openpattern of my shop, col: dualopenfreq of each enemy

profit=np.array([np.sum(np.array([P[i][freq[i]] for i in range(N)]))  for freq in dualopenfreq])
#row:openpattern of my shop, col:profit
print(np.max(profit))

Submission status: Accepted

Solution code:
from itertools import product

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 = []
for p in product([0,1],repeat = 10):
	if sum(p) == 0:
		continue
	res = 0
	for i in range(n):
		cnt = 0
		for j in range(10):
			if p[j]:
				cnt += F[i][j]
		res += P[i][cnt]
	ans.append(res)
print(max(ans))

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
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):
  tmp=0
  for j in range(n):
    f,p=F[j],P[j]
    cnt=0
    for k in range(10):
      if (i>>k)&1 and f[k]:
        cnt+= 1
    tmp+=p[cnt]
  ans=max(ans,tmp)
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):
  tmp=0
  for j in range(n):
    cnt=0
    f=F[j]
    p=P[j]
    for k in range(10):
      if (i>>k)&1:
        cnt+= 1 if f[k] else 0
    tmp+=p[cnt]
  ans=max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
F = [''.join(list(map(str, input().split()))) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = [0]*((1<<10)-1)
for i in range(1, 1<<10):
    count = 0
    for j in range(N):
        count += P[j][format(int(F[j], 2)&i, 'b').count('1')]
    ans[i-1] = count
print(max(ans))

Submission status: Accepted

Solution code:
N = int(input())
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
P = []
for i in range(N):
  P.append(list(map(int,input().split())))
def Base_10_to_n(X,n):
  if (int(X/n)):
    return Base_10_to_n(int(X/n),n)+str(X%n)
  return str(X%n)
n = 2
ans = -(10**10)
for X in range(1,n**10+1):
  STR = Base_10_to_n(X,n).zfill(10)
  cur = 0
  for i in range(N):
    cnt = 0
    for j in range(10):
      if int(STR[j]) == L[i][j] == 1:
        cnt += 1
    cur += P[i][cnt]
  if ans <= cur:
    ans = cur
print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    f = []
    for _ in range(n):
        x = [int(s) for s in input().split()]
        p = 0
        for y in x:
            p <<= 1
            p |= y
        f.append(p)
    p = [[int(s) for s in input().split()] for _ in range(n)]
    print(solve(n, f, p))

def solve(n, f, p):
    m = float('-inf') 
    for i in range(1, 1024):
        q = 0
        for j in range(n):
            c = ones(f[j] & i)
            q += p[j][c]
        m = max(m, q)
    return m

def ones(n):
    m = 0
    while n != 0:
        if n & 0x01 != 0:
            m += 1
        n >>= 1
    return m

main()

Submission status: Accepted

Solution code:
MAX_TIME = 10

N = int(input())

# F[店のインデックス]
# 他の店
# 選択する時間帯を2進法で表現したもの
F = [sum(v << MAX_TIME - k - 1 for k, v
         in enumerate(map(int, input().split())))
     for i in range(N)]

# P[店のインデックス][合致した時間帯の数]
# 利益
P = [[int(j) for j in input().split()] for i in range(N)]


def main():
    # 予めビットをカウントしておく
    pattern = [sum(i >> j & 1 for j in range(MAX_TIME))
               for i in range(2 ** MAX_TIME)]

    # 営業時間帯 すべて試す
    # 最低でも ひとつの時間帯
    print(max(sum(
        P[j][pattern[F[j] & i]] for j in range(N))
        for i in range(1, 2 ** MAX_TIME)))

    return


main()

Submission status: Accepted

Solution code:
MAX_TIME = 10

N = int(input())

F = [int(input().replace(" ", ""), 2) for i in range(N)]

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


def main():
    # 1 から 2 ** MAX_TIME - 1
    # 営業時間帯 最低でも ひとつの時間帯
    # 選択する時間帯を2進法で表現したもの

    # F[店のインデックス]
    # 他の店
    # 選択する時間帯を2進法で表現したもの

    # P[店のインデックス][合致した時間帯の数]
    # 利益
    print(max(sum(
        [p[bin(f & i).count("1")] for f, p in zip(F, P)])
        for i in range(1, 2 ** MAX_TIME)))

    return


main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)
#def input():
#    return sys.stdin.readline()[:-1]

'''
n=int(input())
for i in range(n):
    a[i]=int(input())
    a[i],b[i]=map(int,input().split())
a=[int(x) for x in input().split()]
n,m=map(int,input.split())
from operator import itemgetter
a = [(1, "c", 1), (1, "b", 3), (2, "a", 0), (1, "a", 2)]
print(sorted(a))  # 0 番目の要素でソート、先頭の要素が同じなら 1 番目以降の要素も見る
print(sorted(a, key=itemgetter(0)))  # 0 番目の要素だけでソート
print(sorted(a, key=itemgetter(0, 2)))  # 0 番目と 2 番目の要素でソート
print(sorted(a, key=lambda x: x[0] * x[2]))  # 0 番目の要素 * 2 番目の要素でソート
print(sorted(a, reverse=True))  # 降順にソート
a.sort()  # 破壊的にソート、sorted() よりも高速
try: # エラーキャッチ list index out of range
    for i in range():
        k=b[i]
except IndexError as e:
    print(i)
'''

test_data1 = '''\
1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2
'''

test_data2 = '''\
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
'''

test_data3 = '''\

'''
td_num=1

def GetTestData(index):
    if index==1:
        return test_data1
    if index==2:
        return test_data2
    if index==3:
        return test_data3

if False:
    with open("../test.txt", mode='w') as f:
        f.write(GetTestData(td_num))
    with open("../test.txt") as f:
        # Start Input code ---------------------------------------
        n=int(f.readline())
        g=[[] for x in range(n)]
        p=[[] for x in range(n)]
        for i in range(n):
            g[i]=[int(x) for x in f.readline().split()]
        for i in range(n):
            p[i]=[int(x) for x in f.readline().split()]
        # End Input code ---------------------------------------
else:
    for i in range(1):
        # Start Input code ---------------------------------------
        n=int(input())
        g=[[] for x in range(n)]
        p=[[] for x in range(n)]
        for i in range(n):
            g[i]=[int(x) for x in input().split()]
        for i in range(n):
            p[i]=[int(x) for x in input().split()]
        # End Input code ---------------------------------------
#print('n,g,p=',n,g,p)
o=[0]*10
ans=-10**17
try: # エラーキャッチ list index out of range

    for i in range(1,2**10):
        e=0
        for shop in range(n):
            cnt=0
            for t in range(10):
                o[t]=(i%(2**(t+1))) // (2**t)
                cnt+=g[shop][t]*o[t]
            e+=p[shop][cnt]
        ans=max(ans,e)
        #if e==8: print(o,g[shop],cnt,e)
    print(ans)
except IndexError as e:
    print(i,shop,cnt)

Submission status: Accepted

Solution code:
from sys import stdin

input = stdin.readline

MAX_TIME = 10

N = int(input())

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

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


def main():
    ans = -11000000001

    # 営業時間帯 最低でも ひとつの時間帯
    # 選択パターン
    for i in range(1, 2 ** MAX_TIME):
        tmp = 0

        # 他の店
        for j in range(N):
            # 各時間帯
            cnt = sum([F[j][k] for k in range(MAX_TIME) if i >> k & 1])
            tmp += P[j][cnt]

        ans = max(ans, tmp)

    print(ans)
    return


main()

Submission status: Accepted

Solution code:
MAX_TIME = 10

N = int(input())

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

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


def main():
    ans = -11000000001

    # 営業時間帯 最低でも ひとつの時間帯
    # 選択パターン
    for i in range(1, 2 ** MAX_TIME):
        tmp = 0

        # 他の店
        for j in range(N):
            # 各時間帯
            cnt = sum([F[j][k] for k in range(MAX_TIME) if i >> k & 1])
            tmp += P[j][cnt]

        ans = max(ans, tmp)

    print(ans)
    return


main()

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random

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



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

F = np.array(F)
P = np.array(P)


def cal_val(shop_num,open_time):
    same_time = int(np.dot(F[shop_num],open_time.T))
    # print(open_time)
    return P[shop_num,same_time]
#
# def to2digit(i):
#     open_time = np.zeros([10])
#     for count in range(10):
#         if i%2==1:
#             open_time[count] = 1
#         i = i//2
#     return open_time



values = []
ans = -10**10
for i in range(1,2**10):
    open_time = np.zeros([10])
    for j in range(10):
        if i%2==1:
            open_time[j] = 1
        i = i//2
    value = 0
    for shop_num in range(n):
        value += cal_val(shop_num,open_time)
    values.append(value)
    ans = max(ans,value)


print(ans)
# print(max(values))

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc080/tasks/abc080_c

import itertools
import collections
import bisect


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

    # print(F)
    # print(P)

    # big value
    INF = int(1e15)
    ans = -INF
    pattern = 1024  # 1 をパターンの数だけ左にシフトする
    for i in range(1, pattern):
        score = 0
        # print(bin(i))
        for s in range(N):
            matched = 0
            f = F[s]
            p = P[s]
            # print(f)
            # print(p)
            for j in range(10):
                if (i >> j) & 1:  # open
                    matched += 1 if f[j] else 0

            # print("s = {} match = {}".format(s, matched))
            score += p[matched]
        # print(score)
        ans = max(ans, score)

    print(ans)


if __name__ == '__main__':
    main()

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

print(ans)

Submission status: Accepted

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


for i in range(1,1024):
    openTime = list(map(int, list("{:0>10}".format(bin(i)[2:]))))
    thisProfit = 0
    for n in range(N):
        shopOpneTime = F[n]
        shopProfit = P[n]
        counter = 0
        for j in range(10):
            if((shopOpneTime[j])and(openTime[j])):
                 counter += 1
        thisProfit += shopProfit[counter]
    maxProfit = max(thisProfit, maxProfit)

print(maxProfit)

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):
    b, s = i, 0
    cnt = [0 for _ in range(N)]
    while b > 0:
        if b & 1:
            for j in range(N):
                cnt[j] += F[j][s]
        s += 1
        b >>= 1
    sub_ans = 0
    for j in range(N):
        sub_ans += P[j][cnt[j]]
    ans = max(ans, sub_ans)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
F = [list(map(int, input().strip().split())) for i in range(N)]
P = [list(map(int, input().strip().split())) for i in range(N)]
maxProfit = -1000000000



for i in range(1,1024):
    openTime = list(map(int, list("{:0>10}".format(bin(i)[2:]))))
    thisProfit = 0
    for n in range(N):
        shopOpneTime = F[n]
        shopProfit = P[n]
        counter = 0
        for j in range(10):
            if((shopOpneTime[j])and(openTime[j])):
                 counter += 1
        thisProfit += shopProfit[counter]
    maxProfit = max(thisProfit, maxProfit)

print(maxProfit)

Submission status: Accepted

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

#C
def C():
    N = I()
    F = LIR(N)
    P = LIR(N)
    ans = -1*float("INF")
    kaiten = list((itertools.product([0,1], repeat=10)))
    del kaiten[0]
    for patern in kaiten:
        i = list(patern)
        anskaiten = [0 for i in range(N)]
        for youbi, n in enumerate(i):
            if n == 1:
                for nn,f in enumerate(F):
                    if f[youbi] == 1:
                        anskaiten[nn] += 1
        ansb = 0
        #print(anskaiten, end="")
        for k, p in enumerate(P):
            ansb += p[anskaiten[k]]
        ans = max(ans, ansb)
    print(ans)
        
if __name__ == '__main__':
    C()

Submission status: Accepted

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

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = I()
    f = LIR(n)
    po = [1]*11
    for i in range(n):
        k = 0
        p = 1
        for j in range(10):
            k += p*f[i][j]
            p *= 2
            po[j+1] = p
        f[i] = k
    p = LIR(n)
    ans = -float("inf")
    for i in range(1,1024):
        k = 0
        for j in range(n):
            c = i&f[j]
            s = 0
            for l in po:
                if c&l:s += 1
            k += p[j][s]
        ans = max(ans,k)
    print(ans)
#D
def D():
    n,C = LI()
    T = [[0 for i in range(200002)] for j in range(C)]
    for i in range(n):
        s,t,c = LI()
        c -= 1
        T[c][2*s] += 1
        T[c][2*t+1] -= 1
    for c in range(C):
        for i in range(200000):
            T[c][i+1] += T[c][i]
    ans = 0
    for i in range(200000):
        k = 0
        for c in range(C):
            if T[c][i]:k += 1
        ans = max(ans, k)
    print(ans)
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

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

Submission status: Accepted

Solution code:
def bit_index(n: int) -> list:
    '''n の立っているビットのインデックスを返します。
    '''
    res = []
    idx = 0
    while n > 0:
        if n & 1:
            res.append(idx)
        n >>= 1
        idx += 1
    return res


def shopping_street(N: int, F: list, P: list) -> int:
    max_profits = -float('inf')
    # 10 ビットのフラグの t 番目が立っている時、
    # t // 2 曜日の時間帯 t % 2 に出店するとする。
    # 少なくとも 1 回は出店しないといけないので、0
    # は除く。
    for i in range(1, 1 << 10):
        open_times = bit_index(i)
        profits = 0
        # 各店舗と出店日がかぶる回数を数える。
        for n in range(N):
            shop_count = sum(F[n][t] for t in open_times)
            profits += P[n][shop_count]
        max_profits = max(max_profits, profits)
    return max_profits


if __name__ == "__main__":
    N = int(input())
    F = [[int(s) for s in input().split()] for _ in range(N)]
    P = [[int(s) for s in input().split()] for _ in range(N)]
    ans = shopping_street(N, F, P)
    print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import product

def main():
    input = sys.stdin.readline
    N = int(input())
    F = []
    for _ in range(N):
        A = list(map(int, input().split()))
        F.append(A)

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

    ans = -10**9
    l = [0, 1]
    shop = list(product(l, repeat=10))
    for s in shop:
        if sum(s) == 0:
            continue

        cur = 0
        for i in range(N):
            f = F[i]
            n = sum([f[j] * s[j] for j in range(10)])
            cur += P[i][n]

        ans = max(ans, cur)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
L1 = []
L2 = []
ans = -10**10
for _ in range(N):
    l = list(map(int,input().split()))
    L1.append(l)
for _ in range(N):
    l = list(map(int,input().split()))
    L2.append(l)

for j in range(1,1024):
    b = format(j,'b').zfill(10)
    price = 0
    for k in range(N):
        cnt = 0
        for i in range(10):
            if L1[k][i] == int(b[i]) == 1:
                cnt += 1
        price += L2[k][cnt]
    ans = max(ans,price)
print(ans)

Submission status: Accepted

Solution code:
import itertools
c=itertools.product([0,1], repeat=10)
n=int(input())
f=[list(map(int, input().split())) for i in range(n)]
p=[list(map(int, input().split())) for i in range(n)]
ans=-10**10
def C(ci):
    cnt=[0]*n
    for x in range(n):
        for y in range(10):
            if ci[y]==1 and f[x][y]==1:
                cnt[x]+=1
    res=0
    for z in range(n):
        res+=p[z][cnt[z]]
    return res
for ci in c:
    if all(i ==0 for i in ci):
        continue
    ans=max(ans, C(ci))
print(ans)

Submission status: Accepted

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

l = ['0','1']
def n_ary1(l,d): # リストl中の文字でd桁を全列挙(sorted)
    if d == 1:
        return(l)
    ll = n_ary1(l,d-1)
    lll = []
    for i in l:
        for j in ll:
            lll.append(i+j)
            #lll.append(int(i+j)) ## n進数の場合
    return(lll)

def l_and(l1,l2):
    s = 0
    for i in range(len(l1)):
        s += int(l1[i])&int(l2[i])
    return(s)

JJ = n_ary1(l,10)[1:]
ans = -float('inf')
for J in JJ:
    C = [l_and(F[i],J) for i in range(N)]
    p = sum([P[i][C[i]] for i in range(N)])
    ans = max(ans,p)
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)]
x = - 10 ** 10
for a in product((0, 1), repeat=10):
    if not any(a):
        continue
    num = 0
    for f, p in zip(F, P):
        c = sum(map(lambda z: z[0] * z[1], zip(a, f)))
        num += p[c]
    x = max(x, num)
print(x)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000)

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)]
INF = 10 ** 9

def dfs(s):
    if len(s) == 10:
        value = -INF
        if "1" in s:
            value = 0
            c = [0 for i in range(N)]
            for i in range(5):
                for j in range(2):
                    for k in range(N):
                        if int(s[2*i+j]) * F[k][2*i+j]:
                            c[k] += 1
            for i in range(N):
                value += P[i][c[i]]
        return value
    else:
        return max(dfs(s+"0"), dfs(s+"1"))

print(dfs(""))

Submission status: Accepted

Solution code:
#080-C 
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
F=[int(input().replace(" ",""), 2) for _ in range(n)]
P=[IL() for i in range(n)]
ans=-pow(10,10)
for i in range(1,pow(2,10)):
    t=0
    for f,p in zip(F,P):
        t+=p[bin(f&i).count("1")]
    ans=max(ans,t)
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)]

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

Submission status: Accepted

Solution code:
import itertools


def main():
    N = int(input())
    F = [tuple(map(int, input().split())) for _ in range(N)]
    P = [tuple(map(int, input().split())) for _ in range(N)]
    ans = -float("inf")
    for ptn in itertools.product((0, 1), repeat=10):
        if ptn == (0, 0, 0, 0, 0, 0, 0, 0, 0, 0):
            continue
        tmp = 0
        for i in range(N):
            common = sum([ptn[x] * F[i][x] for x in range(10)])
            tmp += P[i][common]
        ans = max(tmp, ans)
    print(ans)


if __name__ == "__main__":
    main()

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 = -(1e9+7)
for i in range(1, 2**10):
  b = 0
  for f, p in zip(F, P):
    b += p[bin(f&i).count("1")]
  ans = max(ans, b)
print(ans)

Submission status: Accepted

Solution code:
def calc(pat, F, P):
    ans = 0
    both = [0 for i in range(N)]
    for i in range(10):
        if pat[i] == 1:
            for j in range(N):
                if F[j][i] == 1:
                    both[j] += 1
    for i in range(N):
        ans += P[i][both[i]]
    return ans

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

zenbu = 2**10
res = []
for i in range(1, zenbu):
    pat = []
    bit = i
    for j in range(10):
        pat.append(bit % 2)
        bit //= 2
    res.append(calc(pat, F, P))

print(str(max(res)))

Submission status: Accepted

Solution code:
n = int(input())

a = [list(map(int,input().split())) for i in range(n)]
b = [list(map(int,input().split())) for i in range(n)]
c = [0 for i in range(n)]
su = 0
co = -1*1<<40
for i in range(1,1<<10):
    ii = i
    for j in range(n):
        for k in range(10):
            if (a[j][k]<<k) & i != 0:
                c[j] += 1
    for j in range(n):
        su += b[j][c[j]]

    co = max(co,su)
    su = 0
    c = [0 for i in range(n)]

print(co)

Submission status: Accepted

Solution code:
import itertools
import numpy as np
N = int(input())
F = np.array([list(map(int, input().split())) for _ in range(N)])
P = [list(map(int, input().split())) for _ in range(N)]
benefit = -float("inf")

for i in itertools.product((0, 1), repeat=10):
    if sum(i) != 0:
        C = np.array(list(i)) + F
        pre_benefit = 0
        for j in range(N):
            count = len(np.where(C[j]==2)[0])
            pre_benefit += P[j][count]
        if benefit < pre_benefit:
            benefit = pre_benefit
print(benefit)

Submission status: Accepted

Solution code:
import itertools

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

for i in range(N):
    p = list(map(int,input().split()))
    P.append(p)


ans = -float("inf")

for comb in itertools.product((0,1), repeat=10):
    rieki = 0
    for i in range(N):
        tmp_list = [a + b for a, b in zip(F[i], list(comb))]
        rieki += P[i][tmp_list.count(2)]

    if rieki > ans and sum(comb) != 0:
        ans = rieki

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)]
# zen tansaku
maxscore = -10**9
def bittolist(x):
    ret = []
    for _ in range(10):
        ret.append(x%2)
        x //= 2
    return ret
for i in range(1, 1024):
    open = bittolist(i)
    score = 0
    for store in range(n):
        count = 0
        for time in range(10):
            if f[store][time] == 1 and open[time] == 1:
                count += 1
        score += p[store][count]
    maxscore = max(maxscore, score)
print(maxscore)

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N=ri()
F=[rl() for _ in range(N)]
P=[rl() for _ in range(N)]
ans = -INF

import itertools
for d in itertools.product(range(2),repeat=10):
    if sum(d) == 0: continue
    res = 0
    for i in range(N):
        res += P[i][sum(map(lambda x,y:x&y, F[i], d))]
    ans = max(ans,res)

print(ans)

Submission status: Accepted

Solution code:
from itertools import product


def BothAreOpen(arrange1, arrange2):
    counter = 0
    for element in zip(arrange1, arrange2):
        if element == (1, 1):
            counter += 1
    return counter


N = int(input())
OpeningHours = [list(map(int, input().split())) for i in range(N)]
Profits = [list(map(int, input().split())) for i in range(N)]

ans = -1000000000000000000000000

for MyShop in product([0, 1], repeat=10):
    if MyShop == tuple([0] * 10):
        continue

    chofuku = []
    for OtherStore in OpeningHours:
        chofuku.append(BothAreOpen(MyShop, OtherStore))

    x = sum([Profits[i][chofuku[i]] for i in range(N)])
    if x > ans:
        ans = x

print(ans)

Submission status: Accepted

Solution code:
#from collections import Counter
N=int(input())
F=list(int(input().replace(" ",""),2) for i in range(N))
P=list(list(map(int,input().split())) for i in range(N))
ans=-(1<<40)
for bit in range(1,1<<10):
    tmp = 0
    for i in range(N):
        tmp+=P[i][bin(bit&F[i]).count('1')]
    ans = max(ans,tmp)
print(ans)