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:
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


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


def readstrs():
    return input().split()


def main():
    N = readint()
    F = [''.join(readstrs()) for _ in range(N)]
    P = [list(readnums()) for _ in range(N)]
    ans = -(10 ** 9)
    for i in range(1, 1024):
        val = 0
        for j, f in enumerate(F):
            c = bin(i & int(f, 2))[2:]
            v = sum(map(int, c))
            val += P[j][v]

        ans = max(ans, val)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())

F = []
for _ in range(N):
    mask = 0
    for f in map(int, input().split()):
        mask <<= 1
        mask |= f
    F.append(mask)

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

def calc(state):
    ret = 0
    for f, ps in zip(F, P):
        f &= state
        cnt = 0
        while f > 0:
            cnt += f % 2
            f //= 2
        ret += ps[cnt]
    return ret

ans = -10**18
for state in range(1, 1 << 10):
    ans = max(ans, calc(state))
print(ans)

Submission status: Accepted

Solution code:
def main():
    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)]
    bit = 1<<10
    res = -10**10
    for i in range(1,bit):
        chk = [0]*n
        cnt = 0
        for j in range(10):
            if (i>>j)&1:
                for k in range(n):
                    if f[k][j] == 1:
                        chk[k] += 1
        for l in range(n):
            cnt += p[l][chk[l]]
        res = max(res,cnt)
    print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import product
N=int(input())
F = [[[0 for _ in range(3)] for _ in range(6)] for _ in range(N+1)]
for i in range(1,N+1):
    A = list(map(int,input().split()))
    F[i][1][1] = A[0]
    F[i][1][2] = A[1]
    F[i][2][1] = A[2]
    F[i][2][2] = A[3]
    F[i][3][1] = A[4]
    F[i][3][2] = A[5]
    F[i][4][1] = A[6]
    F[i][4][2] = A[7]
    F[i][5][1] = A[8]
    F[i][5][2] = A[9]
P = [[0 for _ in range(11)] for _ in range(N+1)]
for i in range(1,N+1):
    P[i] = list(map(int,input().split()))
pmax = -10**10
for x in product((0,1),repeat=10):
    if sum(x)>0:
        G = [[0 for _ in range(3)] for _ in range(6)]
        G[1][1] = x[0]
        G[1][2] = x[1]
        G[2][1] = x[2]
        G[2][2] = x[3]
        G[3][1] = x[4]
        G[3][2] = x[5]
        G[4][1] = x[6]
        G[4][2] = x[7]
        G[5][1] = x[8]
        G[5][2] = x[9]
        p = 0
        for i in range(1,N+1):
            cnt = 0
            for j in range(1,6):
                for k in range(1,3):
                    if F[i][j][k]==1 and G[j][k]==1:
                        cnt += 1
            p += P[i][cnt]
        pmax = max(pmax,p)
print(pmax)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n = INT()
f = [LIST() for _ in range(n)]
p = [LIST() for _ in range(n)]

def func(i, arr):
    if i == 10:
        if sum(arr) == 0:
            return -inf
        pp = 0
        for i in range(n):
            cnt = 0
            for j in range(10):
                if arr[j] == 1 and f[i][j] == 1:
                    cnt += 1
            pp += p[i][cnt]
        return pp
    tmp = deepcopy(arr)
    tmp[i] = 1
    return max(func(i + 1, arr), func(i + 1, tmp))

print(func(0, [0 for _ in range(10)]))

Submission status: Accepted

Solution code:
import sys
from itertools import product

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    F = [list(map(int, input().split())) for _ in range(n)]
    P = [list(map(int, input().split())) for _ in range(n)]

    res = -f_inf
    for pattern in product([0, 1], repeat=10):
        if sum(pattern) == 0:
            continue

        score = 0
        for f, p in zip(F, P):
            cnt = 0
            for i in range(10):
                if pattern[i] == f[i] == 1:
                    cnt += 1
            score += p[cnt]

        res = max(res, score)

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
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)]
    answer = -float("inf")
    for i in range(1, pow(2, 10)):
        now = 0
        cnt = [0 for _ in range(n)]
        for j in range(10):
            if (i >> j) & 1:
                for k in range(n):
                    if f[k][j]:
                        cnt[k] += 1
        for j in range(n):
            now += p[j][cnt[j]]
        answer = max(answer, now)
    print(answer)


if __name__ == '__main__':
    main()

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)]
INF = 10**18
ans = -INF
for schedule in product([0, 1], repeat=10):
    if 1 not in schedule:
        continue
    p_sum = 0
    for i, f in enumerate(F):
        cnt = 0
        for x, y in zip(schedule, f):
            if x == y == 1:
                cnt += 1
        p_sum += P[i][cnt]
    if ans < p_sum:
        ans = p_sum
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 ** 18
for i in range(1, 2 ** 10):
    tmp = 0
    lst = [0] * N
    for j in range(10): #時間帯
        if (i >> j) & 1: #開けるとした時
            for k in range(N):
                lst[k] += F[k][j]
    for k in range(N):
        tmp += P[k][lst[k]]
    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 = -float('inf')

for i in range(1, 1024):
    B = bin(i)[2::]
    count = [0]*N
    for i, b in enumerate(str(B[::-1])):
      if b == "1":
        for j, f in enumerate(F):
          if f[i] == 1:
            count[j] += 1
    l=0
    for p, c in zip(P, count):
        l += p[c]
    ans = max(ans, l)
print(ans)

Submission status: Accepted

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

all_cand = []
for i in range(2**10):
  p_m_list = [False for i in range(10)]
  for j in range(10):
    if ((i >>j) & 1):
      p_m_list[j] = True
  all_cand.append(p_m_list)
all_cand.pop(0)
result_list = []

for cand in all_cand:
  result = 0
  for j in range(n):
    c = 0
    for i in range(10):
      if cand[i] == True and f_list[j][i] == 1:
        c += 1
    result += p_list[j][c]
  result_list.append(result)
  
print(max(result_list))

Submission status: Accepted

Solution code:
import itertools

n = int(input())
F = [None for i in range(n)]
P = [None for i in range(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()))
comb = list(itertools.product([0,1],repeat=10))
comb.pop(0)
# print(F)
# print(P)
# print(comb)

ans = -float("INF")
for i in comb:
    koho = 0
    for j in range(n):
        count = 0
        for k in range(10):
            if i[k]==1 and F[j][k]==1:
                count+=1
        koho += P[j][count]
    ans = max(ans,koho)

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    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)]
    profit = -10**10
    # bit全探索
    # https://qiita.com/gogotealove/items/11f9e83218926211083a#%E4%BE%8B%E9%A1%8C-1
    n = 10
    # 昇順での探索だよ
    for i in range(1, 2 ** n):
        bag = [0] * N
        cnt = 0

        """        
        10進数表記　2進数表記
        0           000
        1           001
        2           010
        3           011
        4           100
        5           101
        6           110
        7           111
        """

        for j in range(n):  # このループが一番のポイント
            if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
                for k in range(N):
                    if F[k][j] == 1:
                        bag[k] += 1
        for l in range(N):
            cnt += P[l][bag[l]]
        profit = max(profit, cnt)
    print(profit)


resolve()

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)]
ma=-10000000000000
for i in range(1,2**10):
    check=[0]*n
    for j in range(10):
        if (i>>j) & 1:
            for k in range(n):
                check[k]+=f[k][j]
    ma_sub=0
    for i in range(n):
        ma_sub+=p[i][check[i]]
    ma=max(ma,ma_sub)
print(ma)

Submission status: Accepted

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

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

print(answer)

Submission status: Accepted

Solution code:
n=int(input())
f=[]
P=[]
for i in range(n):
    a=list(map(int,input().split()))
    f.append(a)
for i in range(n):
    a=list(map(int, input().split()))
    P.append(a)
from itertools import product
ans=-(10**10)
for p in product([0, 1], repeat = 10):
    if sum(p)!=0:
        ret = 0
        for i in range(n):
            cnt = 0
            for j in range(10):
                if p[j] == f[i][j] and p[j] == 1:
                    cnt += 1
            ret += P[i][cnt]
        ans = max(ans, ret)
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from itertools import product

n = int(readline())
f = [list(map(int, readline().split())) for _ in range(n)]
p = [list(map(int, readline().split())) for _ in range(n)]
ans = -float('inf')
for bit in list(product([0, 1], repeat=10))[1:]:
    v = 0
    for ff, pp in zip(f, p):
        cnt = 0
        for i, check in enumerate(ff):
            if bit[i] == check == 1:
                cnt += 1
        v += pp[cnt]
    if ans < v:
        ans = v
print(ans)

Submission status: Accepted

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

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

ans=-1*sys.maxsize
for i in range(1, 2**10):
  temp=0
  for shop in range(n):
    cnt=0
    for j in range(10):
      if (i>>j & 1 and f[shop][j] == 1):
        cnt+=1
    temp+=p[shop][cnt]
  ans=max(ans,temp)
print(ans)

Submission status: Accepted

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

def main():
    N = int(readline())
    F = []
    for _ in range(N):
        inp = list(map(int, readline().rstrip().split()))
        F.append(set([i for i, e in enumerate(inp) if e]))

    P = [list(map(int, readline().rstrip().split())) for _ in range(N)]
    ans = -10**10
    for i in range(1, 2**10):
        b = bin(i)[2:].zfill(10)
        t = set([j for j, e in enumerate(b) if e == '1'])
        pro = 0
        for f, p in zip(F, P):
            d = f & t
            pro += p[len(d)]
        ans = max(ans, pro)
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
f = [int("".join(input().split()),base=2) for _ in range(n)]
p = [list(map(int,input().split())) for _ in range(n)]
ans = -10**10

for i in range(1,1<<10):
  profit = 0
  for j in range(n):
    cnt = bin(i&f[j]).count("1")
    profit += p[j][cnt]
  ans = max(ans,profit)
print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

ans = - (1 << 30)
for i in range(1 << 10):
    profit = 0
    ok = False
    for j in range(N):
        cnt = bin(i & F[j]).count("1")
        if cnt > 0:
            ok = True
        profit += P[j][cnt]

    if ok:
        ans = max(ans, profit)

print(ans)

Submission status: Accepted

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

ans = -1 * float('inf')
for i in range(1, 2**10):
    tmp = 0
    for j in range(N):
        product = i & int(F[j], base=2)
        c = bin(product).count('1')
        tmp += P[j][c]
    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)]

s = [list(map(int,bin(x)[2:].zfill(10))) for x in range(1,2**10)]
c = 0
ans = 0
max = -1000000000
for k in range(2**10-1):
    for i in range(n):
        for j in range(10):
            c += f[i][j]*s[k][j]
        ans += p[i][c]
        c=0
    if ans > max:
        max = ans
    ans = 0
print(max)

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
#F i,j,k 店i　曜日j 時間帯k
#P 店iと両方回転している時間帯の数がci P：　利益
F=[]
for i in range(N):
    f=list(map(int, input().split()))
    F.append(f)
F=np.array(F)

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

#N*10
ans=-np.inf
for b in range(1,2**10):
    C=np.zeros(N)
    for i in range(10):
        if b>>i&1==1:
            now=F[:,i]
            C+=now
    subnow=0
    #print(C)
    for j,c in enumerate(C):
        subnow+=P[j][int(c)]
    ans=max(ans, subnow)

print(ans)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
N = int(input())
shop = [int(readline().replace(' ', ''), 2) for _ in range(N)]
profits = [list(map(int, readline().split())) for _ in range(N)]
ans = -10**20
for bit in range(1, 1<<10+1):
    profit = 0
    cnt = 0
    for s, p in zip(shop, profits):
        num = bin(bit&s).count('1')
        if num:
            cnt += 1
        profit += p[num]
    if cnt and ans < profit:
        ans = profit
print(ans)

Submission status: Accepted

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

num_patterns = 2 ** 10
max_profit = -float('inf')
for pattern_10 in range(1,num_patterns):
    pattern_ls = [0] * 10
    for d in range(10):
        if ((pattern_10 >> d) & 1):
            pattern_ls[d] = 1
    profit = 0
    for shop_ind in range(n):
        the_shop_open = shop_open[shop_ind]
        both_open_times = 0
        for time in range(10):
            if the_shop_open[time] == 1 and pattern_ls[time] == 1:
                both_open_times += 1
        profit += profit_ls[shop_ind][both_open_times]
    max_profit = max(max_profit, profit)
print(max_profit)

Submission status: Accepted

Solution code:
from itertools import product

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

ret = -10 ** 18
for p in product([0, 1], repeat=10):
    if sum(p) == 0:
        continue
    t = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            if p[j]:
                cnt += f_lst[i][j]
        t += p_lst[i][cnt]
    ret = max(ret, t)
print(ret)

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


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

    ans = -1000000000
    for am in range(2 ** 5):
        for pm in range(2 ** 5):
            opens = [0 for _ in range(10)]
            for i in range(5):
                if ((am >> i) & 1):
                    opens[2 * i] = 1
                if ((pm >> i) & 1):
                    opens[2 * i + 1] = 1
            if sum(opens) == 0:
                continue
            res = 0
            for i, fs in enumerate(F):
                cnt = 0
                for f, o in zip(fs, opens):
                    if f == 1 and o == 1:
                        cnt += 1
                res += P[i][cnt]
            ans = max(ans, res)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
N=int(input())

fmat=[]
for i in range(N):
  array=list(map(int,input().split()))
  fmat.append(array)
  
pmat=[]
for i in range(N):
  array=list(map(int,input().split()))
  pmat.append(array)
#print(fmat)
#print(pmat)

max_answer=-10**9
for bit in itertools.product(range(2),repeat=10):
  if sum(bit)==0:
    continue
    
  answer=0  
  for i in range(N):
    both_num=0
    for j in range(10):
      if bit[j]==1 and fmat[i][j]==1:
        both_num+=1
    
    answer+=pmat[i][both_num]
    
  max_answer=max(max_answer,answer)
  
print(max_answer)

Submission status: Accepted

Solution code:
n=int(input())
f=[]
P=[]
for i in range(n):
    a=list(map(int,input().split()))
    f.append(a)
for i in range(n):
    a=list(map(int, input().split()))
    P.append(a)
from itertools import product
ans=-(10**10)
for p in product([0, 1], repeat = 10):
    if sum(p)!=0:
        ret = 0
        for i in range(n):
            cnt = 0
            for j in range(10):
                if p[j] == f[i][j] and p[j] == 1:
                    cnt += 1
            ret += P[i][cnt]
        ans = max(ans, ret)
print(ans)

Submission status: Accepted

Solution code:
import itertools

n=int(input())
f=[[]]*n
for i in range(n):
    fij=list(map(int,input().split()))
#    f[i].append(fij)
    f[i]=fij
p=[[]]*n
for i in range(n):
    pij=list(map(int,input().split()))
    p[i]=pij
    
pmax=-10**11
for a in itertools.product([0,1], repeat=10):
    if sum(a)==0:
        continue
    psum=0
    for ni in range(n):
        k=0
        for i in range(10):
            if f[ni][i]==1 and a[i]==1:
                k+=1
        psum=psum+p[ni][k] 
    pmax=max(pmax,psum)   

print(pmax)

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 = 0
for ff, i in enumerate(itertools.product([0, 1], repeat=10)):
    if sum(i) == 0:
        continue
    point = 0
    for idx, f in enumerate(F):
        count = 0
        for a, b in zip(i, f):
            count += a * b
        point += P[idx][count]

    if ff == 1:
        ans = point
    else:
        # if max(ans, point) == point:
        #     print(i)
        ans = max(ans, point)

print(ans)

Submission status: Accepted

Solution code:
def bitCount(bits):
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555)
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333)
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f)
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff)
    return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff)


N = int(input())
F = [0] * N
for i in range(N):
    F[i] = int("".join(input().split()), 2)

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

maxx = -9999999999999999
for bina in range(1, 2**10):
    total = 0
    for i in range(N):
        zyu = bina & F[i]
        total += P[i][bitCount(zyu)]
    maxx = max(total, maxx)

print(maxx)

Submission status: Accepted

Solution code:
N = int(input())
f = []
for i in range(N):
    F = map(str, input().split())
    f.append("0B" + ''.join(F))
P = [list(map(int, input().split())) for i in range(N)]

ans = -float("inf")
for bit in range(1, 2 ** 10):
    profit = 0  
    for i in range(N):    
        c = bin( bit & int(f[i], 0) )
        index = c.count('1')
        profit += P[i][index]
    ans= max(ans, profit)

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

answer = -float("inf")
for i in range(1, 2**10):
    temporary = 0
    for j in range(n):
        c = bin(i & F[j]).count("1")
        temporary += P[j][c]
    answer = max(answer, temporary)

print(answer)

Submission status: Accepted

Solution code:
N = int(input())
F = [[] for _ in range(N)]
P = [[] for _ in range(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 = []

# 全探査
K = 2 # 選択肢の数
M = 10 # 問題の個数
for i in range(K**M):
    TF=[0]*M

    for j in range(M):
        TF[M-j-1] = i % K
        i //= K
    
    benefit = 0
    if sum(TF) != 0:
        for j in range(N):
            c = 0
            for k in range(10):
                if TF[k] == 1 and F[j][k] == 1:
                    c += 1
            benefit += P[j][c]
        ans.append(benefit)

print(max(ans))

Submission status: Accepted

Solution code:
N = int(input())
F = [[] for _ in range(N)]
P = [[] for _ in range(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 = []

# 全探査
K = 2 # 選択肢の数
M = 10 # 問題の個数
for i in range(K**M):
    TF=[0]*M

    for j in range(M):
        TF[M-j-1] = i % K
        i //= K
    
    benefit = 0
    if sum(TF) != 0:
        for j in range(N):
            c = 0
            for k in range(10):
                if TF[k] == 1 and F[j][k] == 1:
                    c += 1
            benefit += P[j][c]
        ans.append(benefit)

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

maxprofit = -(10 ** 10)
for i in range(1, 2 ** 10):
    conflicts = [0] * N
    for t in range(10):
        opening = bool(i & (1 << t))
        for j in range(N):
            if F[j][t] and opening:
                conflicts[j] += 1
    profit = 0
    for j in range(N):
        profit += P[j][conflicts[j]]
    if maxprofit < profit:
        maxprofit = profit
        maxstate = i

print(maxprofit)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
chk = []
for _ in range(n):
  f = input().split()
  chk.append(int(''.join(f),2))

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

import collections
ans = -float('inf')
for i in range(1,2**10):
  que = 0
  for j,cj in enumerate(chk):
    d = format(i & cj,'b')
    c = collections.Counter(d)
    que += p[j][c['1']]
  ans = max(ans,que)
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
chk = []
for _ in range(n):
  f = input().split()
  chk.append(int(''.join(f),2))
chk = tuple(chk)

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

import collections
ans = -float('inf')
for i in range(1,2**10):
  que = 0
  for j,cj in enumerate(chk):
    d = format(i & cj,'b')
    c = collections.Counter(d)
    que += p[j][c['1']]
  ans = max(ans,que)
print(ans)

Submission status: Accepted

Solution code:
import itertools
n=int(input())
f=[tuple(map(int,input().split())) for _ in range(n)]
p=[tuple(map(int,input().split())) for _ in range(n)]
ll=list(itertools.product(range(2),repeat=10))[1:]
ans=-10**10
for l in ll:
    t=0
    for i in range(n):
        c=0
        for j in range(10):
            if l[j]==1:
                if f[i][j]==l[j]:
                    c+=1
        t+=p[i][c]
    ans=max(ans,t)
print(ans)

Submission status: Accepted

Solution code:
data = int(input())

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

max_score = -float('inf')
for pattern_i in range(1, 2**10):
  op_num = [0]*data
  for pos_i in range(10):
    if pattern_i & 1<<pos_i:
      for n_i in range(data):
        op_num[n_i] += F[n_i][pos_i]
  max_score = max(max_score, sum([p_i[op_num_i] for p_i, op_num_i in zip(P, op_num)]))

print(max_score)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    ans = -INF

    from itertools import product, chain

    for bit in range(1, 1 << 10):
        c = [0] * n
        for time in range(10):
            if bit >> time & 1:
                for shopnum, shopopen in enumerate(f):
                    if shopopen[time]:
                        c[shopnum] += 1

        prof = 0

        for shopnum in range(n):
            prof += p[shopnum][c[shopnum]]

        ans = max(ans, prof)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def return_C(i, List):
    j = ''.join(List)
    j = int(j, 2)
    AND = i & j
    return bin(AND).count('1')

ans = - 10 ** 10
for i in range(1, 2 ** 10):
    temp = 0
    for j in range(N):
        c = return_C(i, F[j])
        temp += P[j][c]
    ans = max(ans, temp)

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

bit = 1<<10
ans = -10**10
for i in range(1,bit):
    tmp = 0
    for j in range(n):
        cj = 0
        for k in range(10):
            cj+= f[j][k] & (i>>k)
        tmp += p[j][cj]
    ans = max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
f=['' for _ in range(n)]
p=[[] for _ in range(n)]
for i in range(n):
  f[i]=int(''.join(input().split()),2)
for i in range(n):
  p[i]=list(map(int,input().split()))
ans=-10**9
for i in range(1,1024):
  tmp=0
  for j in range(n):
    k=str(format(i&f[j],'010b')).count('1')
    tmp+=p[j][k]
  ans=max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import itertools

n = int(readline())
f = [list(map(int, readline().split())) for _ in range(n)]
p = [list(map(int, readline().split())) for _ in range(n)]
bit = list(itertools.product([0, 1], repeat=10))
ans = -float('inf')
bit.pop(0)
for i in range(2 ** 10 - 1):
    memo = 0
    flag = False
    for j in range(n):
        cnt = 0
        for k in range(10):
            if bit[i][k] == f[j][k] == 1:
                cnt += 1
        if cnt != 0:
            flag = True
        memo += p[j][cnt]
    if flag:
        ans = max(ans, memo)
print(ans)