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: Wrong Answer

Solution code:
from itertools import product
N=int(input())
F=[list(map(int, input().split())) for i in range(N)]
P=[list(map(int, input().split())) for i in range(N)]
l=list(product(range(2),repeat=10))
del l[0]
a=-10**7
for i in range(1023):
    t=0
    for j in range(N):
        c=0
        for k in range(10):
            c+=F[j][k] and l[i][k]
        t+=P[j][c]
    if t>a:
        a=t
print(a)

Submission status: Wrong Answer

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 = - 10e7
for i in range(1, 1024):
    x = list(map(int, (bin(i)[2:].zfill(10))))
    _ans = 0
    for j in range(n):
        c = sum(map(lambda x, y: x*y, x, f[j]))
        _ans += p[j][c]
    ans = max(ans, _ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
f = [int(input().replace(" ","")) for i in range(n)] #数にしてしまう
p = [list(map(int,input().split())) for i in range(n)]
ans = -10**12
for i in range(1,1024):
    #print("i=",i)
    temp = 0
    for j in range(n): #j = 0,1,2,..,n-1で店番号
        fi = f[j]
        ci = bin(fi&i).count("1") #bin()は2進法表記のstrになる。
        temp += p[j][ci]
    #print(temp)
    ans = max(ans,temp)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
f = [int(input().replace(" ","")) for i in range(n)] #数にしてしまう
p = [list(map(int,input().split())) for i in range(n)]
ans = -10**12
for i in range(1,1024):
    #print("i=",i)
    temp = 0
    for j in range(n): #j = 0,1,2,..,n-1で店番号
        fi = f[j]
        ci = bin(fi&j).count("1") #bin()は2進法表記のstrになる。
        temp += p[j][ci]
    #print(temp)
    ans = max(ans,temp)
print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    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())))
    mx = -1e9
    for i in range(1, 1 << 10):
        benefit = 0
        for j in range(n):
            f = F[j]
            counter = 0
            for k in range(10):
                if (i >> k & f[k]) == 1:
                    counter += 1
            benefit += P[j][counter]
        mx = max(mx, benefit)
    print(mx)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    F = [[[0 for _ in range(2)] for _ in range(5)] for _ in range(N)]
    for i in range(N):
        tmp = inputList()
        for j,val in enumerate(tmp):
            ind = j // 2
            if j % 2 == 0:
                F[i][ind][0] = val
            else:
                F[i][ind][1] = val
                
    P = []
    for i in range(N):
        tmp = inputList()
        P.append(tmp)
        
    ans = -100000000
    for i in range(1, 2**10):
        ans_tmp = [0 for _ in range(N)]
        for j in [1,2,2**2,2**3,2**4,2**5,2**6,2**7,2**8,2**9]:
            tmp = j & i
            ind = 0
            hi = 0
            
            if tmp == 0:
                ind = -1
                hi = -1
            elif tmp == 1:
                ind = 0
                hi = 0
            elif tmp == 2:
                ind = 0
                hi = 1
            elif tmp == 4:
                ind = 1
                hi = 0
            elif tmp == 8:
                ind = 1
                hi = 1
            elif tmp == 16:
                ind = 2
                hi = 0
            elif tmp == 32:
                ind = 2
                hi = 1
            elif tmp == 64:
                ind = 3
                hi = 0
            elif tmp == 128:
                ind = 3
                hi = 1
            elif tmp == 256:
                ind = 4
                hi = 0
            elif tmp == 512:
                ind = 4
                hi = 1
                
            if ind != -1:
                for k in range(N):
                    tmp2 = F[k][ind][hi]
                    #if k == 0:
                        #print("{} {} {}".format(k,ind,hi))
                    #if i == 683:
                        #print("{} {} {}".format(k,ind,hi))
                    if tmp2 == 1:
                        ans_tmp[k] += 1
                        
        a_tmp = 0
        for j in range(N):
            a_tmp += P[j][ans_tmp[j]]
        if ans < a_tmp:
            ans = a_tmp
        
    print(ans)
            	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import sys

def main():
	n = int(input())
	f = []
	for i in range(n):
		f.append(list(map(int,input().split())))
	p = []
	for i in range(n):
		p.append(list(map(int,input().split())))
	ans = -sys.maxsize
	for x10 in range(2,2**10-1):
		x2 = base_10_to_n(x10,2)
		for _ in range(10-len(x2)):	
			x2 = '0' + x2
		benefit = 0
		for j in range(n):
			count = 0
			for k in range(10):
				if(f[j][k] == 1 and x2[k] == '1'):
					count+=f[j][k]
			benefit+=p[j][count]
		if(ans<benefit): ans = benefit
	print(ans)

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

Submission status: Wrong Answer

Solution code:
def main():
	n = int(input())
	f = []
	for i in range(n):
		f.append(list(map(int,input().split())))
	p = []
	for i in range(n):
		p.append(list(map(int,input().split())))
	ans = -2147483649
	for x10 in range(1,2**10-1):
		x2 = base_10_to_n(x10,2)
		for _ in range(10-len(x2)):	
			x2 = '0' + x2
		benefit = 0
		for j in range(n):
			count = 0
			for k in range(10):
				if(f[j][k] == 1 and x2[k] == '1'):
					count+=f[j][k]
			benefit+=p[j][count]
		if(ans<benefit): ans = benefit
	print(ans)

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

Submission status: Wrong Answer

Solution code:
def main():
	n = int(input())
	f = []
	for i in range(n):
		f.append(list(map(int,input().split())))
	p = []
	for i in range(n):
		p.append(list(map(int,input().split())))
	ans = -2147483648
	for x10 in range(1,2**10-1):
		x2 = base_10_to_n(x10,2)
		for _ in range(10-len(x2)):	
			x2 = '0' + x2
		benefit = 0
		for j in range(n):
			count = 0
			for k in range(10):
				if(f[j][k] == 1 and x2[k] == '1'):
					count+=f[j][k]
			benefit+=p[j][count]
		if(ans<benefit): ans = benefit
	print(ans)

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

Submission status: Wrong Answer

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)]
n_timetable = len(lst_F[0])
lst_joisino = [0] * n_timetable


def score(src, F, P):
    cnt = 0
    for i, j in zip(src, F):
        if i == j == 1:
            cnt += 1
    return P[cnt]
# print(score([1,1,0,1,0,0,0,1,0,1], lst_F[0], lst_P[0]))


def dfs(pos):
    if pos == n_timetable:
        ret = 0
        for i in range(N):
            if lst_joisino == [0] * n_timetable:
                continue
            p = score(lst_joisino, lst_F[i], lst_P[i])
            ret += p
        return ret
    lst_joisino[pos] = 0
    ret0 = dfs(pos + 1)
    lst_joisino[pos] = 1
    ret1 = dfs(pos + 1)
    return max(ret0, ret1)


print(dfs(0))

Submission status: Wrong Answer

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

time_lis = [0] * N
profit = [0] * N
for n in range(N):
    time_lis[n] = list(map(int, input().split()))
for n in range(N):
    profit[n] = list(map(int, input().split()))

ans = 0
always_zero = True
for n in range(N):
    count_1 = len([i for i in time_lis[n] if i == 1])
    tmp= max(profit[n][:count_1 + 1])
    ans += tmp
    if profit[n].index(tmp) != 0:
        always_zero = False
if always_zero:
    max_prof = sorted([(item[0], item[1]) for item in profit], key=lambda x: -x[1])
    print(ans - max_prof[0][0] + max_prof[0][1])
    sys.exit()
print(ans)

Submission status: Wrong Answer

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

time_lis = [0] * N
profit = [0] * N
for n in range(N):
    time_lis[n] = list(map(int, input().split()))
for n in range(N):
    profit[n] = list(map(int, input().split()))

ans = 0
always_zero = True
for n in range(N):
    count_1 = len([i for i in time_lis[n] if i == 1])
    tmp= max(profit[n][:count_1 + 1])
    ans += tmp
    if profit[n].index(tmp) != 0:
        always_zero = False
if always_zero:
    max_prof = [item[1] for item in profit]
    print(max(max_prof))
    sys.exit()
print(ans)

Submission status: Wrong Answer

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

# print(f)
# print(p)
ans=-(10**8)

for i in range(1,2**10):
    list=[0]*n
    earn=0
    for j in range(10):
        for k in range(n):
            if i&(1<<j) and f[k][j]==1:
                list[k]+=1
    
    for k in range(n):
        earn+=p[k][list[k]]
    
    ans=max(ans, earn)
print(ans)

Submission status: Wrong Answer

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

# print(f)
# print(p)
ans=-(10**8)

for i in range(1,2**10):
    list=[0]*n
    earn=0
    for j in range(10):
        for k in range(n):
            if i&(2**j) and f[k][j]==1:
                list[k]+=1
    
    for k in range(n):
        earn+=p[k][list[k]]
    
    ans=max(ans, earn)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
F,P,F0=[],[],[]
ans=-10**8-1
for b in range(1,2**10):
    F0.append(format(b,'10b'))
for _ in range(N):
    F.append(list(input().split()))
for _ in range(N):
    P.append(list(map(int,input().split())))

for c in F0:
    benefit=0
    for i in range(N):
        counter=0
        for j in range(10):
            if c[j]=="1" and F[i][j]=="1":counter+=1
        benefit+=P[i][counter]
    ans=max(ans,benefit)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
flist = []
for _ in range(n):
    flist.append([int(f) for f in input().split()])

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

def commonSum(a_l, b_l):
    """共通要素を返す"""
    cnt = 0
    for a, b in zip(a_l, b_l):
        if a == b and a == 1:
            cnt += 1
    return cnt

# 初期値
profit = -10**7
for open in range(1, 2**10):
    openlist = [int(i) for i in format(open, 'b').zfill(10)]

    # 各店との利益を求める
    prof = 0
    for i in range(n):
        common = commonSum(flist[i], openlist)
        prof += plist[i][common]
    if profit < prof:
      profit = prof
print(profit)

Submission status: Wrong Answer

Solution code:
n = int(input())
flist = []
for _ in range(n):
    flist.append([int(f) for f in input().split()])

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


def commonSum(a_l, b_l):
    """共通要素を返す"""
    cnt = 0
    for a, b in zip(a_l, b_l):
        if a == b and a == 1:
            cnt += 1
    return cnt


# 初期値
profit = -10**7
for open in range(1, 2**10):
    openlist = [int(i) for i in format(open, 'b').zfill(10)]

    # 各店との利益を求める
    prof = 0
    for i in range(n):
        common = commonSum(flist[i], openlist)
        prof += plist[i][common]
    profit = max(profit, prof)
print(profit)

Submission status: Wrong Answer

Solution code:
n = int(input())
flist = []
for _ in range(n):
    flist.append([int(f) for f in input().split()])

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

# 共通要素を返す
def commonSum(a_l, b_l):
    cnt = 0
    for i in range(10):
        if a_l[i] == b_l[i] == 1:
            cnt += 1
    return cnt

# 初期値
profit = -10**7
for open in range(1, 2**10):
    openlist = [int(i) for i in format(open, 'b').zfill(10)]

    # 各店との利益を求める
    prof = 0
    for i in range(n):
        common = commonSum(flist[i], openlist)
        prof += plist[i][common]
    profit = max(profit, prof)
print(profit)

Submission status: Wrong Answer

Solution code:
n = int(input())
f_matrix = [[0]*10]*n
p_matrix = [[0]*11]*n
f_matrix = [[int(i) for i in input().split()] for _ in range(n)]
p_matrix = [[int(i) for i in input().split()] for _ in range(n)]

ans = -10**6
for i in range(1, 2**10):
  tmp = 0
  for j in range(n):
    c = 0
    for k in range(10):
      if i>>k & 1 and f_matrix[j][k] is 1:
        c += 1
    tmp += p_matrix[j][c]
    #print(tmp)
  ans = max(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
f_matrix = [[0]*10]*n
p_matrix = [[0]*11]*n
f_matrix = [[int(i) for i in input().split()] for _ in range(n)]
p_matrix = [[int(i) for i in input().split()] for _ in range(n)]

ans = -10**6
for i in range(1, 2**10):
  
  for j in range(n):
    c = 0
    tmp = 0
    for k in range(10):
      if i>>k & 1 and f_matrix[j][k] is 1:
        c += 1
    tmp += p_matrix[j][c]
  ans = max(ans, tmp)
print(ans)

Submission status: Wrong Answer

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

# 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 = -float("INF")
ans = 0
for i in range(1, 10):
    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: Wrong Answer

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, 10):
    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: Wrong Answer

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 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: Wrong Answer

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**8
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: Wrong Answer

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: Wrong Answer

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

sumP=0
zeroshop=0
nextmax=[]
for i in range(N):
    n=sum(F[i])
    maxP=max(P[i][:n+1])
    nextmax.append(max(P[i][1:n+1]))
    sumP+=maxP
    if P[i][:n+1].index(maxP)!=0:
        zeroshop=1
if zeroshop==0:
    nextn=nextmax.index(max(nextmax))
    sumP=sumP-P[nextn][0]+max(nextmax)
print(sumP)

Submission status: Wrong Answer

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

sumP=0
zeroshop=0
for i in range(N):
    n=sum(F[i])
    maxP=max(P[i][:n+1])
    if zeroshop==0 and P[i][:n+1].index(maxP)==0 :
        zeroshop=1
        sumP+=max(P[i][1:n+1])
    else:
        sumP+=max(P[i][:n+1])
print(sumP)

Submission status: Wrong Answer

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)]
sum_p = []
cnt = 0
minn = []
for i in range(N):
    cnt_open = F[i].count(1)
    max_p = max(P[i][0:cnt_open+1])
    min_p = min(P[i][1:cnt_open+1])
    sum_p.append(max_p)
    minn.append(min_p)
    
    if max_p == P[i][0]:
        cnt += 1
if cnt == N:
    print(min(minn))
else:
    print(sum(sum_p))

Submission status: Wrong Answer

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: Wrong Answer

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 ** 7
    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: Wrong Answer

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 -10000000
        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: Wrong Answer

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] * 10


def dfs(pos):
    if pos == 10:
        if a.count(0) == 10:
            return -10000000
        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: Wrong Answer

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):
  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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#ABC080C
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for j in range(N)]
ans =0
for i in range(N):
    profits = 0
    for j in range(10):
        profits += P[i][j] 
    ans = max(ans, profits)
print(ans)