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, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N = INT()
F = [LIST() for _ in range(N)]
P = [LIST() for _ in range(N)]

ans = -INF
for x in product([0, 1], repeat=10):
	x = list(x)
	if 1 in x:
		profit = 0
		for i in range(N):
			common = sum([x[j]*F[i][j] for j in range(10)])
			profit += P[i][common]
		ans = max(ans, profit)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
arr = [list(map(int, input().split())) for i in range(n)]
arm = [list(map(int, input().split())) for j in range(n)]  # 入力

ans = -9999999999  # 最小
for item in range(1, 1024):  # 2 ** 10 == 1024
    fund = 0
    for i in range(n):  # 店の数
        cou = 0  # かぶる数
        for x in range(10):  # 月-金(5) * 2
            if (item >> x) % 2 == 1 and arr[i][x] == 1:  # その時間で被るかどうか
                cou += 1
        fund += arm[i][cou]
    ans = max(ans, fund)  # 最大値更新

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
list_FF = []

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

list_PP = []

for i in range(N):
  list_P = list(map(int, input().split()))
  list_PP.append(list_P)  
  
count = 1
quota = 0

for i in range(N):
  quota+= list_PP[i][list_FF[i].count(1)]

maxquota = quota
    
while count < 2** 10:
  l = list(bin(count))
  lc_tdc = l[2:]
  l_tdc = []
  while lc_tdc:
    l_tdc.append(int(lc_tdc.pop(0)))
  
  while len(l_tdc) < 10:
    l_tdc.insert(0, 0)

  quota = 0
  
  for i in range(N):
    corresp = 0
    for j in range(10):
      corresp+= l_tdc[j]* list_FF[i][j]
    quota+= list_PP[i][corresp]
  maxquota = max(quota, maxquota)
      
  count+= 1

print(maxquota)

Submission status: Accepted

Solution code:
def count_c(li1, li2):
    c = 0
    for i in range(10):
        if li1[i] == 1 and li1[i] == li2[i]:
            c += 1
    return c


n = int(input())
open_time_list = [list(map(int, input().split())) for _ in range(n)]
profit_list = [list(map(int, input().split())) for _ in range(n)]
ans = -10000000000000000000000000000000000
# [1, 0, 1, 0, 0, 0, 1, 1, 0, 1]総当たり
for i in range(1, 2 ** 10):
    f_list_joisino = list(map(int, list(format(i, 'b').zfill(10))))
    temp_profit = 0
    for profit_index, f_list in enumerate(open_time_list):
        temp_profit += profit_list[profit_index][count_c(
            f_list, f_list_joisino)]
    if ans < temp_profit:
        ans = temp_profit

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n = 10
bit_base = 2#bit_base^nの全探査になる. 
def Base_10_to_n(X, n):#10進数をbit_base進数に変換
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
  
def main():
  N = int(input())
  F = []
  for i in range(N):
    F.append(list(map(int, input().split())))
  F = np.array(F)
  P = []
  for i in range(N):
    P.append(list(map(int, input().split())))
  ans = -1*10**9
  for i in range(bit_base**n):
    if i == 0: continue
    s = Base_10_to_n(i, bit_base)
    s = s.zfill(n)
    for num, j in enumerate(s):
      ans_temp = 0
      s = list(s)
      s = np.array([int(i) for i in s])
      C = np.sum(F*s, axis = 1)
      for k,c in enumerate(C):
        ans_temp += (P[k][c])
      ans = max(ans, ans_temp)
  print(ans)
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
#店1:月1 月2 火1 火曜2...
#店2:月1 ... 金2
#みたいな入力
from itertools import accumulate
n = int(input())
lis = []
for i in range(n):
    A=[int(i) for i in input().split()]
    lis.append(A)
ans = [0]*10
lis2 = []
for i in range(n):
    p = [int(i) for i in input().split()]
    lis2.append(p)

#時間帯bit(i)で営業する場合を見るのでbit全探索
ans = -10000000000
for i in range(1,1<<10):
    kaburi = [0]*n#状態iで店を開く時に被ってる店舗を1~Nごとに記録する　kaburi[i]:店iと何個被ってるか
    tmp = 0
    for j in range(11):
        if(i & 1<<j):
            for k in range(n):
                if lis[k][j]:
                    kaburi[k]+=1
    for j in range(n):
        tmp += lis2[j][kaburi[j]]

    ans = max(tmp, ans)
print(ans)

Submission status: Accepted

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

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())

    def count_both_opened(pattern, seq):
        cnt = 0
        for i in range(len(pattern)):
            if pattern[i] == 1 and seq[i] == 1:
                cnt += 1
        return cnt
    
    
    n = ii()
    opened = [lmi() for _ in range(n)]
    profit = [lmi() for _ in range(n)]

    max_profit = -inf
    for pattern in product([1, 0], repeat=10):
        money = 0
        if any(pattern):
            for i in range(n):
                cnt = count_both_opened(pattern, opened[i])
                money += profit[i][cnt]
            # print(f"{pattern} {money}")
            max_profit = max(max_profit, money)

    print(max_profit)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
F = list()
P = list()
ans = - 10**10
for i in range(N):
  F.append(list(map(int, input().split())))
for i in range(N):
  P.append(list(map(int, input().split())))
for i in range(1, 1<<10):
  shop = list()
  cnt = [0]*N
  tmp = 0
  for j in range(10):
    if i>>j & 1:
      shop.append(j)
  for s in range(N):
    for p in shop:
      if(F[s][p] == 1):
        cnt[s] += 1
    tmp += P[s][cnt[s]]
  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, 2**10):
  c = [0] * N
  for j in range(10):
    if i>>j & 1:
      for k in range(N):
        c[k] += F[k][j]
  profit = sum([P[k][c[k]] for k in range(N)])
  ans = max(ans, profit)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

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

INF = 1e100
ans = -1 * INF
for i in range(2**10):
    ch = [0] * 10
    cnt = 0
    for j in range(10):
        if (i >> j) & 1:
            ch[j] = 1
            cnt += 1
    if not cnt:
        continue
    total = 0
    for k in range(n):
        ct = 0
        for l in range(10):
            if opens[k][l] and ch[l]:
                ct += 1
        total += score[k][ct]
    ans = max(ans, total)

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
F = ILL(N)
P = ILL(N)

for i in range(N):
  F[i] = base_n_to_10(sum(F[i][j]*10**j for j in range(10)),2)
  
ans = -INF
for b in range(1,1<<10):
  rieki = 0
  for i in range(N):
    match = count_bit(F[i] & b)
    rieki += P[i][match]
  ans = max(ans,rieki)
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import product


def main():
    N = int(input())
    F = [list(map(int, input().split(' '))) for _ in range(N)]
    P = [list(map(int, input().split(' '))) for _ in range(N)]
    ans = - 10**10
    for pattern in product([0, 1], repeat=10):
        if sum(pattern) == 0:
            continue
        profit = 0
        for n in range(N):
            c = sum([1 if p == f == 1 else 0 for p, f in zip(pattern, F[n])])
            profit += P[n][c]
        ans = max([ans, profit])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
F = []
P = []

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

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

ans = -10 ** 18

# print(F)
for i in range(1, 2**10):
    kaburi_list = []
    tmp = 0
    for tenpo in range(N):
        kaburi = 0
        for j in range(10):
            if i >> j & F[tenpo][-(j+1)] == 1:
                kaburi += 1
        kaburi_list.append(kaburi)
        tmp += P[tenpo][kaburi]
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
F = []
P = []

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

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

ans = -10 ** 9

for i in range(1, 2**10):
    kaburi_list = []
    tmp = 0
    for tenpo in range(N):
        kaburi = 0
        for j in range(10):
            if i >> j & F[tenpo][-(j+1)] == 1:
                kaburi += 1
        kaburi_list.append(kaburi)
        tmp += P[tenpo][kaburi]
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
def solve(n, f_list, p_list):

    ans = [0] * 1024
    
    for i in range(1, 1024):
        for f, p in zip(f_list, p_list):
            c = bin(f & i).count("1")
            ans[i] += p[c]
    
    return max(ans[1:])

if __name__ == "__main__":
    n = int(input())
    f_list = [int("".join(input().split()),2) for i in range(n)]
    p_list = [[int(j) for j in input().split()] for i in range(n)]
    print(solve(n, f_list, p_list))

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
op=[LI() for i in range(n)]
pro=[LI() for i in range(n)]
vals=[]
for j in range(1,2**10):
    ans=0
    common=[0 for i in range(n)]
    for k in range(n):
        for i in range(10):
            x=(j>>i) %2
            common[k]+=x*op[k][i]
        ans+=pro[k][common[k]]
    vals.append(ans)
print(max(vals))

Submission status: Accepted

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


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

    ans = -10**10

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

numf=[]
ansp=0
ans=-float('inf')

for i in range(1,2**10):
  l=str(bin(i)).lstrip("0b")
  ll=list(l.zfill(10))
  ilist=[int(xl) for xl in ll]
  j=0
  ansp=0
  for jlist in f:
    suml=[ilist[k]*jlist[k] for k in range(10)]
    c=sum(suml)
    ansp+=p[j][c]
    j+=1

  ans=max(ans,ansp)

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N = ii()
F = li2(N)
P = li2(N)

B = 2**10

ans = -float('inf')
for i in range(1, B):
    pro = 0
    for j in range(N):
        cnt = 0
        for k in range(11):
            if (i & 1 << k) and F[j][k] == 1:
                cnt += 1
        pro += P[j][cnt]
    ans = max(ans, pro)

print(ans)

Submission status: Accepted

Solution code:

N = int(input())
Shop_info =[list(map(int, input().split())) for _ in range(N)]
Earn = [list(map(int, input().split())) for _ in range(N)]
ans = - float('inf')
for i in range(1,2**10):
    Open = [0] * N
    ansi = 0
    for j in range(10):
        if (i >> j) & 1 == 1:
            for k in range(N):
                if Shop_info[k][j]:
                    Open[k] += 1
    for x, o in enumerate(Open):
        ansi += Earn[x][o]
    ans = max(ans, ansi)
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def is_nth_bit_set(x, n):
    if x & (1 << n):
        return 1
    else:
        return 0


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 = -INF
    total = 2 ** 10
    for pattern in range(1, total):
        joisino = [is_nth_bit_set(pattern, i) for i in range(10)]
        benefit = 0
        for f, p in zip(F, P):
            cnt = 0
            for i, j in zip(joisino, f):
                if i and j:
                    cnt += 1

            benefit += p[cnt]

        if ans < benefit:
            ans = benefit

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())

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

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

ans = -1e10
for bits in range(1<<10):
    if bits == 0: continue

    cnt = [0 for i in range(N)]
    for i in range(10):
        if not (bits>>i & 1): continue 

        for shop in range(N):
            if F[shop][i]: cnt[shop] += 1
    
    benefit = 0
    for shop in range(N):
        benefit += P[shop][cnt[shop]]
    
    ans = max(ans, benefit)

print(ans)

Submission status: Accepted

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    F = [il() for _ in range(N)]
    P = [il() for _ in range(N)]

    ret = -MAX
    for b in range(1, 1 << 10):
        tmp = 0
        for n in range(N):
            o = 0
            for t in range(10):
                if b >> t & 1 and F[n][t] == 1:
                    o += 1
            tmp += P[n][o]
        ret = max(ret, tmp)
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import product

N=int(input())
F=[ [[0 for _ in range(2)] for _ in range(5)] for _ in range(N)]
P= [[0] for _ in range(N)]
total= [[0 for _ in range(5)] for _ in range(2)]

for i in range(N):
  tmp=list( map(int,input().split()) )
  for j in range(5):
    for k in range(2):
      F[i][j][k]=tmp[2*j+k]
for i in range(N):
  P[i]=list(map(int,input().split()))
  
maxi=float("-inf")
combi=product([1,0],repeat=10)

for kumi in combi:
  mini=float("-inf")
  if sum(kumi)==0:
    pass
  else:      
    tmp=0
    for i in range(N):
      summ=0
      for k,open in enumerate(kumi):
        m,n = k//2, k%2
        summ += open * F[i][m][n]
      tmp += P[i][summ]
  maxi=max(maxi,tmp)
      
print(maxi)

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)]
x=[]
for i in range(1,2**10):
    j_open=format(i,'b').zfill(10)
    pro_sum=0
    for j in range(n):
        one_sum=0
        for k in range(10):
            if f[j][k]==1 and j_open[k]=='1':one_sum+=1
        pro_sum+=p[j][one_sum]
    x.append(pro_sum)
print(max(x))

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
F = []
for i in range(N):
    # 各数字をstrに変換
    f = list(map(str, input().split()))
    # join
    falta = ''.join(f)
    # 二進数に変換
    F.append(int(falta, 2))
P = []
for i in range(N):
    p = getList()
    P.append(p)
# -10 ** 7ぐらいだとばか小さい数にならずWA
# ばかでかい数、ばか小さい数にするときは思いっきりばかでかく、小さくしよう
ans = -10 ** 24
# bit全探索するため状態を生成
# 0000000000はダメ（必ず店は開く）
for bit in range(1, 1 << 10):
    sum = 0
    # 各お店と照合
    for i in range(N):
        open = F[i] & bit
        # 二進数表記でのフラグの数をカウント
        index = str(bin(open)).count('1')
        sum += P[i][index]
    ans = max(ans, sum)
print(ans)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
F = []
for i in range(N):
    # 各数字をstrに変換
    f = list(map(str, input().split()))
    # join
    falta = ''.join(f)
    # 二進数に変換
    F.append(int(falta, 2))
P = []
for i in range(N):
    p = getList()
    P.append(p)
ans = -10 ** 24
# 状態を生成
# 0000000000はダメ（必ず店は開く）
for bit in range(1, 1 << 10):
    sum = 0
    # 各お店と照合
    for i in range(N):
        open = F[i] & bit
        # 二進数表記でのフラグの数をカウント
        index = str(bin(open)).count('1')
        sum += P[i][index]
    ans = max(ans, sum)
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 = -(10**10)
for l in itertools.product(range(2), repeat=10):
  if sum(l) == 0:
    continue
  s = 0
  for i in range(n):
    c = 0
    for j in range(10):
      c += l[j] * f[i][j]
    s += p[i][c]
  ans = max(ans, s)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lis = []
for i in range(2 ** 10):
    openls = []
    for j in range(10):
        if ((i >> j) & 1) == 1:
            openls.append(j)
    lis.append(openls)

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

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

ret = - 10 ** 1000

for item in lis:
    if sum(item) == 0:
        continue
    tmp = 0
    for i in range(n):
        same = 0
        for val in item:
            if f[i][val] == 1:
                same += 1
        tmp += p[i][same]
    ret = max(ret, tmp)

print(ret)

Submission status: Accepted

Solution code:
n = int(input())
opn = [list(map(str,input().split())) for i in range(n)]
pnt = [list(map(int,input().split())) for i in range(n)]
ma = -10**100

for i in range(1,1024):
    stt = str(format(i,'010b'))
    p = 0
    for i,sh in enumerate(opn):
        ci = 0
        for j, st in enumerate(sh):
            if stt[j] == "1" and st == "1":
                ci += 1
        p += pnt[i][ci]
    if ma < p:
        ma = p

print(ma)

Submission status: Accepted

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

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") * -1

for i in range(1, 2 ** 10):
    idx = []
    times = []
    for j in range(10):
        if i >> j & 1 == 1:
            idx.append(j)
    for f in F:
        total = 0
        for i in idx:
            if f[i]:
                total += 1
        times.append(total)
    bft = 0
    for p, t in zip(P, times):
        bft += p[t]
    ans = max(bft, ans)

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
timezones = np.array([[int(i) for i in input().split()] for _ in range(n)])
points = np.array([[int(i) for i in input().split()] for _ in range(n)])
max_scores = - float('inf')
for i in range(1, 2 ** 10):
    indices = []
    for j in range(10):
        if i & (1 << j):
            indices.append(j)
    nums = timezones[:, indices].sum(axis=1)
    scores = points[range(n), nums].sum()
    max_scores = max(max_scores, scores)
print(max_scores)