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:
# using main() makes code faster from the point of view of "access to variables in global name-space"
# def main():

# for i, a in enumerate(iterable)
# q, mod = divmod(a, b)
# divmod(x, y) returns the tuple (x//y, x%y)
# manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
import sys
sys.setrecursionlimit(10**7)
from itertools import combinations, permutations # https://docs.python.org/ja/3/library/itertools.html
from math import factorial
def combinations_count(n, r):
    # faster than the following code
    # def combinations_count(n, r):
    #     return factorial(n) // (factorial(n - r) * factorial(r))
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result
def combination_with_repetition_count(n, r):
    return combinations_count(n + r - 1, r)
from collections import deque, Counter # https://docs.python.org/ja/3/library/collections.html#collections.deque
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
from operator import itemgetter # ex: List.sort(key=itemgetter(1))
from functools import reduce
from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
def gcds(numbers):
    return reduce(gcd, numbers)
def lcm(x, y):
    return (x * y) // gcd(x, y)
def lcms(numbers):
    return reduce(lcm, numbers, 1)

# first create factorial_list
# fac_list = mod_factorial_list(n)
INF = 10 ** 18
MOD = 10 ** 6 + 3
modpow = lambda a, n, p = MOD: pow(a, n, p) # Recursive function in python is slow!
def modinv(a, p = MOD):
    # evaluate reciprocal using Fermat's little theorem:
    # a**(p-1) is identical to 1 (mod p) when a and p is coprime
    return modpow(a, p-2, p)
def modinv_list(n, p = MOD):
    if n <= 1:
        return [0,1][:n+1]
    else:
        inv_t = [0,1]
        for i in range(2, n+1):
            inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
        return inv_t
def modfactorial_list(n, p = MOD):
    if n == 0:
        return [1]
    else:
        l = [0] * (n+1)
        tmp = 1
        for i in range(1, n+1):
            tmp = tmp * i % p
            l[i] = tmp
        return l
def modcomb(n, k, fac_list = [], p = MOD):
    # fac_list = modfactorial_list(100)
    # print(modcomb(100, 5, modfactorial_list(100)))
    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    if len(fac_list) <= n:
        a = factorial(n) % p
        b = factorial(k) % p
        c = factorial(n-k) % p
    else:
        a = fac_list[n]
        b = fac_list[k]
        c = fac_list[n-k]
    return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
def modadd(a, b, p = MOD):
    return (a + b) % MOD
def modsub(a, b, p = MOD):
    return (a - b) % p
def modmul(a, b, p = MOD):
    return ((a % p) * (b % p)) % p
def moddiv(a, b, p = MOD):
    return modmul(a, modpow(b, p-2, p))


# initialize variables and set inputs
#initialize variables
    # to initialize list, use [0] * n
    # to initialize two dimentional array, use [[0] * N for _ in range(N)]
# set inputs
    # open(0).read() is a convenient method:
    # ex) n, m, *x = map(int, open(0).read().split())
    #     min(x[::2]) - max(x[1::2])
    # ex2) *x, = map(int, open(0).read().split())
    #     don't forget to add comma after *x if only one variable is used
# set test data
# sys.stdin = open('sample.txt') # for test
# functions used
r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split())
R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)]
Rmap = lambda: map(int, r().split())
# set inputs
N = int(r())
F = [R() for _ in range(N)]
P = [R() for _ in range(N)]
A = [0] * N
# calculate and output
    # output pattern
    # ex1) print(*l) => when l = [2, 5, 6], printed 2 5 6
maxans = -INF
ans = 0
for i in range(1, 11):
    for j in combinations(range(10), i):
        point = 0
        for l in range(N):
            tmp = 0
            for k in j:
                tmp += F[l][k]
            point += P[l][tmp]
        maxans = max(maxans, point)
print(maxans)


# if __name__ == '__main__':
#     main()

Submission status: Accepted

Solution code:
N = int(input())
F = [[int(_) for _ in input().split()] for _ in range(N)]
P = [[int(_) for _ in input().split()] for _ in range(N)]
store = [0] * N
ans = -float('inf')

for i in range(N):
    tmp = 0
    for j in range(10):
        tmp += F[i][j] << j
    store[i] = tmp

for i in range(1, 2**10):
    bene = 0
    for j in range(N):
        bene += P[j][bin(i & store[j]).count('1')]
    
    if bene > ans:
        ans = bene

print(ans)

Submission status: Accepted

Solution code:
l = input().split()
N = int(l[0])

F = [[] for i in range(N)]
P = [[] for i in range(N)]

for i in range(N):
    l = input().split()
    F[i] = [int(x) for x in l]

for i in range(N):
    l = input().split()
    P[i] = [int(x) for x in l]

# print(N, F, P)

max_p = -10**9
for i in range(1, 1024):
    p = 0
    for n in range(N):
        num_open = 0
        for j in range(10):
            is_open = ((i >> j) & 1) == 1
            if is_open and F[n][j] == 1:
                num_open += 1
        p += P[n][num_open]
    max_p = max(p, max_p)

print(max_p)

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 k in range(N)]
x = -(10**10)
for i in range(1,2**10):
    L = [int(b) for b in '{:0>10}'.format(str(bin(i))[2:])]
    y = 0
    for n in range(N):
        m = sum([l&f for l, f in zip(L, F[n])])
        y += P[n][m]
    x = max(x, y)
print(x)

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

m=2**10
gain=-10**10
for i in range(1,2**10):
    x=list(map(int,format(i,'b').zfill(10)))
    sumP=0
    for j in range(N):
        total=sum([a*b for a,b in zip(x,F[j])])
        sumP+=P[j][total]
    gain=max(gain,sumP)
print(gain)

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

jo = []
for a1 in range(2):
    for a2 in range(2):
        for a3 in range(2):
            for a4 in range(2):
                for a5 in range(2):
                    for a6 in range(2):
                        for a7 in range(2):
                            for a8 in range(2):
                                for a9 in range(2):
                                    for a10 in range(2):
                                        if a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 != 0:
                                            jo.append([a1,a2,a3,a4,a5,a6,a7,a8,a9,a10])

a = []

for j in jo:
    ans = 0
    for i in range(n):
        li = []
        for k in range(10):
            li.append(f[i][k]+j[k])
        ans += p[i][li.count(2)]
    a.append(ans)

print(max(a))

Submission status: Accepted

Solution code:
N = int(input())
st_con = [[i for i in map(int,input().split())] for j in range(N)]
rieki = [[i for i in map(int,input().split())] for j in range(N)]

ans = -10**9
for i in range(1,2**10):
    a = 0
    for j in range(N):
        count = 0 
        for h in range(10):
            if (i>>h) & st_con[j][h] and (i>>h) & 1:
                count += 1
        a += rieki[j][count]
    
    if ans < a : ans = a 
print("{}".format(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 = []

for i in range(1, 2**10):
    C = [0] * N
    for j in range(10):
        if (i >> j) & 1 == 1:
            for k, f in enumerate(F):
                if f[j] == 1:
                    C[k] += 1
    pro = 0
    for c, p in zip(C, P):
        pro += p[c]
    ans.append(pro)

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

result = -float('inf')
for i in range(1,1024):
    working = [0 for _ in range(n)]
    for j in range(10):
        if i>>j&1:
            for shop in range(n):
                if f[shop][j]:
                    working[shop] += 1
    benefit = 0
    for shop in range(n):
        benefit += p[shop][working[shop]]

    result = max([result, benefit])

print(result)

Submission status: Accepted

Solution code:
N = int(input())
F = []
for _ in range(N):
    lst = input().split()
    F.append(''.join(lst))
P = []
for _ in range(N):
    P.append(tuple(map(int, input().split())))
ans = -10**12
for bit in range(1, 1 << 10):
    temp = 0
    for i, f in enumerate(F):
        f_dec = int(f, 2)
        both_open = f_dec & bit
        c = format(both_open, 'b').count('1')
        temp += P[i][c]
    ans = max(ans, temp)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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


#bit全探索
ans = -10 ** 9
for i in range(1, 2**10):
    tmp = 0
    c = [0] * N
    for j in range(10):
        if (i >> j) & 1:
            for k in range(N):
                if F[k][j] == 1:
                    c[k] += 1
    for l in range(N):
        tmp += P[l][c[l]]
    ans = max(tmp, ans)

print (ans)

Submission status: Accepted

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

## ビット全探索
solver = []
for i in range(1 << 10): # range(2**10)と同値
    if i == 0:
      continue
    C = [0]*N
    for j in range(10):  # 10個の要素それぞれに対し
        if ((i >> j) & 1) == 1: # iの右からj桁目が1なら
            for k in range(N):
                C[k] += F[k][j] 
    profit = sum([P[k][C[k]] for k in range(N)])
    solver.append(profit)

print(max(solver))

Submission status: Accepted

Solution code:



def main():
    num = int(input())
    open_data = [list(map(int, input().split())) for i in range(num)]
    value_data = [list(map(int, input().split())) for i in range(num)]

    ans = -1 * 10 ** 10

    for i in range(1, 1024):
        open_list = list(map(int, list(bin(i)[2:].zfill(10))))
        kari = 0
        for j in range(num):
            onaji = 0
            for k in range(10):
                if open_list[k] and open_data[j][k]:
                    onaji += 1
            kari += value_data[j][onaji]

        if kari > ans:
            ans = kari

    print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

max_benefit=-10**10
def convert(num):
    res=[]
    for i in range(10):
        res.append(num%2)
        num=num//2
    return res

for opennum in range(1,2**10):
    opentime=convert(opennum)
    benefit=0
    for i in range(n):
        count=0
        for j in range(10):
            if open_other[i][j]==1 and opentime[j]==1:
                count+=1
        benefit+= benefit_other[i][count]
    max_benefit=max(max_benefit,benefit)
print(max_benefit)

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


ans = -float("INF")
for b in range(1, 2**10):
    tmp = 0
    for i in range(n):
        c = 0
        for k in range(10):
            if b&(1<<k) and lst_F[i][k]:
                c += 1
        tmp += lst_P[i][c]
    ans = max(tmp, ans)


print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

Solution code:
n=int(input())
f=[list(map(int,input().split())) for i in range(n)]
p=[list(map(int,input().split())) for i in range(n)]
ans=float("-inf")
for i in range(1,2**10):
    i=list(map(int,list(bin(i)[2:].zfill(10))))
    x,y=0,0
    for j in range(n):
        y=0
        for k in range(10):
            if i[k]==f[j][k]==1:y+=1
        x+=p[j][y]
    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)]
ans = -10**9
for bit in range(1,2**10):
  t = [0]*10
  for k in range(10):
    if bit&(2**k):
      t[k] = 1
  pat = [0]*n
  for a in range(10):
    for b in range(n):
      if f[b][a]&t[a]:
        pat[b] += 1
  ben = 0 
  for x in range(n):
    ben += p[x][pat[x]]
  if ans < ben:
    ans = ben
print(ans)

Submission status: Accepted

Solution code:
import itertools
n=int(input())
f=[list(map(int,input().split())) for i in range(n)]
p=[list(map(int,input().split())) for i in range(n)]
ans=-1000000000
for x in itertools.product([0,1],repeat=10):
    if all(i==0 for i in x):
        continue
    cnt=[0]*n
    tmp=0
    for i in range(n):
        for t in range(10):
            if x[t]==0:continue
            cnt[i]+=f[i][t]
        tmp+=p[i][cnt[i]]
    ans=max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N, F, P):
    # 全探索
    bmax = -INF
    bmax_arg = -1
    for n in range(1, 2**10):
        bene = 0
        # print(n)
        for j in range(N):
            c = bin(int(F[j], 2) & n).count("1")
            bene += P[j][c]
        if bmax < bene:
            bmax = bene
            bmax_arg = n
    print(bmax)


def main():
    N = int(input())
    F = []
    for i in range(N):
        F.append("".join(input().split()))
    P = []
    for i in range(N):
        P.append(list(map(int, input().split())))
    solve(N, F, P)
    pass


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
F=[]
for i in range(N):
    f=list(map(int,input().split()))
    F.append(f)
P=[]
for i in range(N):
    p=list(map(int,input().split()))
    P.append(p)
ans=-10**12
for i in range(1,2**10):
    i=bin(i)[2:].zfill(10)
    res=0
    for n in range(N):
        tmp=0
        for j in range(10):
            if i[j]=="1" and F[n][j]==1:
                tmp+=1
        res+=P[n][tmp]
    ans=max(ans,res)
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())))
    
from itertools import product
joisino_store_product = list(product([0, 1], repeat=10))[1:]

def binary_compare(A, B):
    C = []
    for i, j in zip(A, B):
        if i == 1 and  j == 1:
            C.append(1)
        else:
            C.append(0)
    return C
  
sum_list = []

for joisino_store in joisino_store_product:
    C = []
    priceSum = 0
    
    for F_store in F:
        C.append(sum(binary_compare(joisino_store, F_store)))
    
    for C_num, P_list in zip(C, P):
        priceSum += P_list[C_num]
        
    sum_list.append(priceSum)
    
print(max(sum_list))

Submission status: Accepted

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

x = [int(v, 2) for v in F]
rev = []
for i in range(1, 2 ** 10):
    cnt = [list(bin(i & v)[2:]).count('1') for v in x]
    rev.append(sum([P[j][cnt[j]] for j in range(N)]))
print(max(rev))

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

#print(N,F,P)

ans = -(10**9+7)
for i in range(1, 2**10):
  tmp = 0
  for f, p in zip(F, P):
    tmp += p[bin(f&i).count('1')]
    #print(f,i,p[bin(f&i).count('1')])
  ans = max(ans, tmp)
print(ans)

Submission status: Accepted

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


def dfs(pos):
    if pos == 10:
        if a.count(0) == 20:
            return -1000000000
        score = 0
        for f, p in zip(F, P):
            c = 0
            for aa, ff in zip(a, f):
                if aa == ff == 1:
                    c += 1
            score += p[c]
        return score
    a[pos] = 0
    x = dfs(pos + 1)
    a[pos] = 1
    y = dfs(pos + 1)
    return max(x, y)


def main():
    print(dfs(0))


main()

Submission status: Accepted

Solution code:
def main():
    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, 2 ** 10):
        c = 0
        for f, p in zip(F, P):
            c += p[bin(f & i).count('1')]
        ans = max(ans, c)
    print(ans)


main()

Submission status: Accepted

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

ma = -1e20
for i in range(1, 2 ** 10):
    count = 0
    for f, p in zip(F, P):
        count += p[bin(f & i).count("1")]
    ma = max(ma, count)
print(ma)

Submission status: Accepted

Solution code:
N = int(input())
F = [int(''.join(input().split()), 2) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]
benefit = -10**9
for i in range(1, 2 ** 10):
    b = 0
    for f, p in zip(F, P):
        count = 0
        for j in range(10):
            if (i & f) >> j & 1:
                count += 1
        b += p[count]
    benefit = max(benefit, b)
print(benefit)

Submission status: Accepted

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

ans = float("-inf")
for bit in range(1, 1024):
    sum_p = 0
    for shop in range(N):
        time = bin(F[shop] & bit).count("1")
        sum_p += P[shop][time]

    ans = max(ans, sum_p)

print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    F = []
    P = []
    for i in range(N):
        F.append(list(int(_) for _ in input().split()))
    for i in range(N):
        P.append(list(int(_) for _ in input().split()))
        
    ans = -1 * INF
    for i in range(1,2**10):
        tmp_ans =0
        for j in range(N):
            cnt = 0
            for k in range(len(F[j])):
                if ( i & (1 << k) )and(F[j][k] == 1):
                    cnt +=1
            tmp_ans += P[j][cnt]
        ans = max(ans,tmp_ans)
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import itertools
import numpy as np

input = sys.stdin.readline

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

scores = []
for a in itertools.product(
  *[[0, 1] for _ in range(10)]):
    
    if np.sum(a)==0:
        continue
    
    score = 0
    
    for f, p in zip(F, P):
        m = np.sum([
            int(x==1 and y==1) for x, y 
          in zip(a, f)])
        score += p[m]
    
    scores.append(score)
    
print(np.max(scores))

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)]
score = -10 ** 18

for i in range(1 << 10):
    t = []
    
    for j in range(10):
        if (i >> j) & 1:
            t.append(j)
            
    if t == []:
        continue
        
    s = [0] * N
    for j in range(N):
        p = F[j]
        c = 0
        for tt in t:
            if p[tt] == 1:
                c += 1
        s[j] = P[j][c]
    
    score = max(score, sum(s))
    
print(score)

Submission status: Accepted

Solution code:

def bi(i):
    o = [0]*10
    c = 0
    while i > 0:
        o[c] = i % 2
        i //= 2
        c += 1
    return o

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

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

i = 1
while i < 1024:
    o = bi(i)
    i += 1
    a = 0
    j = 0
    while j < N:
        f = F[j]
        c = C[j]
        a += c[sum([o[x]*f[x] for x in range(10)])]
        j += 1
    v.append(a)

print(max(v))

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)]
print(max(sum(p[j][sum(f[j][x] == "1" and format(i, "010b")[x] == "1" for x in range(10))] for j in range(n)) for i in range(1, 2 ** 10)))

Submission status: Accepted

Solution code:
def mkstring(s):
  if len(s)<10:
    return '0'*(10-len(s))+s
  else:
    return s

n=int(input())
arr1=[''.join(map(str,input().split())) for _ in range(n)]
arr2=[list(map(int,input().split())) for _ in range(n)]
ans=-10**10
for i in range(1,2**10+1):
  s=mkstring(format(i,'b'))
  tmp=0
  for j in range(n):
    cnt=0
    for k in range(10):
      if s[k]=='1' and arr1[j][k]=='1':
        cnt+=1
    tmp+=arr2[j][cnt]
  if ans<tmp:
    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):
    profit = 0
    for j in range(N):
        sim = 0
        for s in range(10):
            if i & (1 << s) and F[j][s]:
                sim += 1
        profit += P[j][sim]
    ans = max(ans, profit)

print(ans)

Submission status: Accepted

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

values_all = []
for a in range(2 ** 10):
    a2 = bin(a)[2:].zfill(10)
    values = 0
    for i in range(n):
        ci = 0
        for j in range(10):
            if f[i][j] == 1 and a2[j] == '1':
                ci += 1
        pici = p[i][ci]
        values += pici
    values_all.append(values)

print(max(values_all[1:]))

Submission status: Accepted

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

ans = -float("inf")
for i in itertools.product((0,1), repeat=10):
  if list(i) == [0] * 10:
    continue
  a = 0
  for j in range(n):
    c = 0
    for k in range(10):
      if i[k] == f[j][k] == 1:
        c += 1
    a += p[j][c]
  ans = max(ans, a)
  
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
F=[int(input().replace(" ", ""), 2) for _ in range(N)]
P=[[int(x) for x in input().split()] for _ in range(N)]
C=[sum(map(int, format(i, "b"))) for i in range(2**10)]
print(max([sum([p[C[f&i]] for f,p in zip(F, P)]) for i in range(1, 2**10)]))

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    fa = [ f() for i in range(n)]
    
    pa = [ f() for i in range(n)]

    mxa = int(-1e9)
    for i in range(1,2**10):
        ans = 0
        for j in range(n):
            cnt = 0
            for k in range(10):
                if i&(1<<k) and fa[j][k]:
                    cnt += 1
            ans += pa[j][cnt]
        mxa = max(mxa, ans)

    print(mxa)
            

solve()

Submission status: Accepted

Solution code:

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

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

    plist = []
    for j in range(n):
        plist.append(list(map(int, input().split())))

    return n, flist, plist


# aとbの1が重複している数を数える
def check_open(a, b):
    c = 0
    for i,j in zip(a, b):
        if i == j == 1:
            c += 1

    return c

# 整数を受け取り、2進数のリストにして返す
def get_pattern(p):
    binary_p = bin(p)[2:]
    list_p = [int(c) for c in binary_p]
    list_p = [0]*(10 - len(list_p)) + list_p
    return list_p


def submit():
    n, flist, plist = read_input()
    max_pattern = 2048
    max_profit = -float('inf')
    for p in range(1, 2048):
        myshop = get_pattern(p)
        profit = 0
        for i in range(n):
            target_shop = flist[i]
            c = check_open(myshop, target_shop)
            profit += plist[i][c]

        if max_profit < profit:
            max_profit = profit

    print(max_profit)

if __name__ == '__main__':
    submit()

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
v = [0] * 10

def culc():
    global ans
    score = 0
    if any(v) == False:
        return
    for i in range(N):
        index = 0
        for j in range(10):
            index += F[i][j] * v[j]
        score += P[i][index]
    ans = max(ans, score)
    return

def dfs(pos):
    if pos == 10:
        culc()
        return

    v[pos] = 0
    dfs(pos+1)
    v[pos] = 1
    dfs(pos+1)

    return

dfs(0)

print(ans)

Submission status: Accepted

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math



def get_c(a, b):
  # a,b の営業時間の個数を返す
  return str(bin(a&b)).count("1")



if __name__ == "__main__":
  ## Input
  N = int(input())
  Fn = []
  Pn = []

  for i in range(N):
    f = list(map(int, input().split()))
    ret = 0
    for i in range(10):
      ret *= 2
      ret += f[i]
    Fn.append(ret)

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

  ## Solve
  ret = -1 * 10**10
  for i in range(1,2**10):
    ans = 0
    for j in range(N):
      ans += Pn[j][get_c(Fn[j],i)]
    ret = max(ret, ans)
  print(ret)

Submission status: Accepted

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


max_benef =-float("inf")

for d in range(1,2**10):
    op = ["-"] * 10  # あらかじめ ["-", "-", "-"] というリストを作っておく
    for j in range(10):
        if ((d >> j) & 1):
            op[10 - 1 - j] = "+"  # フラグが立っていた箇所を "+" で上書き
    
    m =0
    count=[0 for s in range(N)]
    for t in range(10):
        if op[t]=="+":
            for s in range(N):
                if F[s][t]==1:
                    count[s]+=1
    for s in range(N):
        m += P[s][count[s]]
    max_benef = max(m,max_benef)
    
print(max_benef)

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