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:
n = int(input())
F = [[*map(int, input().split())] for _ in range(n)]
P = [[*map(int, input().split())] for _ in range(n)]

def c(i, open_patern):
    ret = 0
    for j in range(10):
        if open_patern>>j & 1: #open my shop
            if F[i][j]: ret += 1 # open your shop
    return ret

ans = -10000000*10
for i in range(1, 1<<10): # open pattern 10bit, i:[0~1,1~1]
    s = 0
    for j in range(n): # your shop
        cj = c(j, i)
        s += P[j][cj]
    ans = max(ans ,s)
print(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())))
maxp=-10**10
for i in range(1,2**10):
  prof=0
  s='{0:b}'.format(i)
  S=[]
  for i in range(len(s)):
    S.append(s[i])
  for i in range(10-len(s)):
    S.append('0')
  for j in range(n):
    count=0
    for k in range(10):
      count+=int(S[k])*F[j][k]
    prof+=P[j][count]
  maxp=max(maxp,prof)
print(maxp)

Submission status: Wrong Answer

Solution code:
from itertools import product
from operator import mul
def main():
    n = int(input())
    f = [tuple(map(int, input().split())) for _ in range(n)]
    p = [tuple(map(int, input().split())) for _ in range(n)]

    patterns = tuple(product([0,1], repeat=10))
    results = []
    for pate in patterns:
        if sum(pate) == 0:
            continue
        res = []
        flag = 0
        for i1, fe in enumerate(f):
            s = sum(tuple(map(mul, pate, fe)))
            if s != 0:
                flag = 1
                res.append(p[i1][s])
            if flag:
                results.append(sum(res))
    print(max(results))
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import numpy as np
import math

N = int(input().rstrip())
shop_open = []
values = []
for i in range(N):
    shop_open.append(np.asarray(list(map(int,input().rstrip().split())), dtype=np.int))
for i in range(N):
    values.append(np.asarray(list(map(int,input().rstrip().split())), dtype=np.int))

def dfs(open_array,max_sales):
    
    if len(open_array) == 10:
        if open_array.count(1) == 0:
            return max_sales
        sales = calc_sales(open_array)
        if sales > max_sales:
            max_sales = sales
        return max_sales

    flag = [0,1]
    for f in flag:
        tmp_ar = open_array.copy()
        tmp_ar.append(f)
        max_sales = dfs(tmp_ar,max_sales)
        
    return max_sales
        
def calc_sales(open_array):
    global shop_open,values
    sales = 0
    for i,ar in enumerate(shop_open):
        both_open = open_array + ar
        c = np.count_nonzero(both_open == 2)
        sales += values[i][c]
    return sales
    

open_ar = []
max_sales = dfs(open_ar,-10**7)
print(max_sales)

Submission status: Wrong Answer

Solution code:
X = open(0).readlines()
n = int(X[0])
F = []
for x in X[1:n+1]:
    F.append(list(map(int, x.split())))
P = []
for x in X[n+1:]:
    P.append(list(map(int, x.split())))

ans = -10**8
for i in range(1, 2**10):
    A = [(i >> j) & 1 for j in range(10)]
    s = 0
    for j in range(n):
        t = sum(p and a for p, a in zip(F[j], A))
        s += P[j][t]
    if ans < s:
        ans = s
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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 1&(j<<i):
            shop.append(j)
    for s in range(n):
        for p in shop:
            if(f[s][p]==1):
                cnt+=1
        tmp+=p[s][cnt[s]]
    ans=max(ans,tmp)
print(ans)

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, idx, m = 0, 0, 0
r = -float("INF")
for i in range(N):
    tmp = max(P[i][:sum(F[i])+1])
    idx += P[i][:sum(F[i])+1].index(tmp)
    ans += tmp

    if r < P[i][0] - max(P[i][1:sum(F[i])+1]):
        r = P[i][0] - max(P[i][1:sum(F[i])+1])

if idx == 0:
    ans -= r

print(ans)

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, idx = 0, 0
for i in range(N):
    tmp = max(P[i][:sum(F[i])+1])
    idx += P[i][:sum(F[i])+1].index(tmp)
    ans += tmp
    m = max(P[i][1:sum(F[i])+1])

if idx == 0:
    ans = m

print(ans)

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 = -9999999
for i in range(1,2**10):
    pfit = 0
    for j in range(N):  
        cnt = 0
        for k in range(10): 
            if (i >> k) & 1 == 1 and F[j][k] == 1:
                 cnt +=1 
        pfit += P[j][cnt]
    ans = max(ans,pfit)
print(ans)

Submission status: Wrong Answer

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

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 = -1 * 10 ** 7

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

Solution code:
n=int(input())
f=[]
p=[]
for i in range(0,n):
  temp=list(map(int,input().split()))
  f.append(temp)
for i in range(0,n):
  temp=list(map(int,input().split()))
  p.append(temp)
ans=-99999999
for i in range(1,2**10):
  temp=0
  for j in range(0,n):
    count=0
    for k in range(0,10):
      if (i&1<<k) and f[j][k]==1:        
        count=count+1
    temp=temp+p[j][count]
  ans=max(ans,temp)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
f=[]
p=[]
for i in range(0,n):
  temp=list(map(int,input().split()))
  f.append(temp)
for i in range(0,n):
  temp=list(map(int,input().split()))
  p.append(temp)
ans=-99999999
for i in range(1,2**10):
  temp=0
  for j in range(0,n):
    count=0
    for k in range(0,10):
      if (i<<j)&1 and f[j][k]==1:        
        count=count+1
    temp=temp+p[j][count]
  ans=max(ans,temp)
print(ans)

Submission status: Wrong Answer

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

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=[]
ans=-float('inf')

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

    ans=max(ans,p[j][c])
    j+=1

print(ans)

Submission status: Wrong Answer

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=[]
ans=0

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

print(ans)

Submission status: Wrong Answer

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 = -100000000
# 状態を生成
# 0000000000はダメ（必ず店は開く）
for bit in range(1, 1 << 10):
    sum = 0
    # 各お店と照合
    for i in range(N):
        open = F[i] & bit
        # 二進数表記でのフラグの数をカウント
        cnt = 0
        for j in range(10):
            if open & (1 << j):
                cnt += 1
        sum += P[i][cnt]
    ans = max(ans, sum)
print(ans)

Submission status: Wrong Answer

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 = -100000000
# 状態を生成
# 0000000000はダメ（必ず店は開く）
for bit in range(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: Wrong Answer

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 = -100000000
# 状態を生成
# 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: Wrong Answer

Solution code:
import numpy as np
N = int(input())
F = np.array(tuple(tuple(map(int, input().split())) for _ in range(N)), dtype=np.int8)
P = np.array(tuple(tuple(map(int, input().split())) for _ in range(N)), dtype=np.int8)
arrange = np.arange(N)
print(max(P[arrange, F[:, np.array(list(map(lambda n: n == "1", format(n, "010b"))), dtype=np.bool)].sum(axis=1)].sum() for n in range(1, 1 << 10)))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
F = np.array(tuple(tuple(map(int, input().split())) for _ in range(N)), dtype=np.int8)
P = np.array(tuple(tuple(map(int, input().split())) for _ in range(N)), dtype=np.int8)
arrange = np.arange(N)
print(max(P[arrange, F[:, list(map(lambda n: n == "1",format(n, "010b")))].sum(axis=1)].sum() for n in range(1, 1 << 10)))

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)]
from itertools import product as pr
x=0
for ch in list(pr([0,1],repeat=10)):
  if 1 not in ch:
    continue
  s=0
  for j in range(n):
    c=0
    t=f[j]
    for k in range(10):
      if ch[k] and t[k]:
        c+=1
    s+=p[j][c]
  x=max(x,s)
print(x)

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=-pow(10,8)
# bit全探索
for i in range(1,2**10):
  s=[]
  for j in range(10):
    if ((i>>j) & 1):#0~9の時間のうち、お姉ちゃんの店が営業する時間
      s.append(j)
  ansi=0
  for j in range(n):
    ansi+=p[j][sum([f[j][si] for si in s])]
  ans=max(ans,ansi)
print(ans)

Submission status: Wrong Answer

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 j, f in enumerate(F):
        val = 0
        for i in range(1, 1024):
            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: Wrong Answer

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 = (10 ** 7 + 1) * (-1)
    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: 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=0
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: Wrong Answer

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

Solution code:
n=int(input())
f=[sum(list(map(int,input().split()))) for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(n)]
ans=[]
for i in range(n):
  kari=-10**6
  for j in range(f[i]+1):
    kari=max(kari,p[i][j])
  ans.append(kari)
cnt=0
for i in range(n):
  if ans[i]!=p[i][0]:
    break
  else:
    cnt+=1
if cnt<n:
  print(sum(ans))
else:
  a=0
  ans=-10**6
  for i in p:
    a+=i[0]
  for i in range(n):
    b=a
    b-=p[i][0]
    kari=-10**6
    for j in range(1,f[i]+1):
      kari=max(kari,p[i][j])
    b+=kari
    ans=max(ans,b)
  print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
f = []
for _ in range(n):
  f.append(sum(map(int,input().split())))
ans = 0
noopen = True
akaji = -100000000
for c in f:
  p = list(map(int,input().split()))
  if c == 0:
    ans += p[0]
  else:
    ans += max(p[0:c+1])
    if noopen:
      if p[0] <= max(p[1:c+1]):
        noopen = False
      akaji = max(akaji,max(p[1:c+1])-p[0])
if noopen:
  ans += akaji
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
f = []
for _ in range(n):
  f.append(list(map(int,input().split())))
ans = 0
noopen = True
akaji = -10000000
for i in range(n):
  p = list(map(int,input().split()))
  c = sum(f[i])
  if c == 0:
    ans += p[0]
  else:
    ans += max(p[0:c+1])
    if noopen:
      if p[0] <= max(p[1:c+1]):
        noopen = False
      akaji = max(akaji,max(p[1:c+1])-p[0])
if noopen:
  ans += akaji
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)]

s = [list(map(int,bin(x)[2:].zfill(10))) for x in range(2**10)]
s.pop(0)
c = 0
ans = 0
max = -10000000
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: Wrong Answer

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):
            closed = False
            opens = [0 for _ in range(10)]
            for i in range(5):
                if not (((am >> i) & 1) or ((pm >> i) & 1)):
                    closed = True
                    break
                if ((am >> i) & 1):
                    opens[2 * i] = 1
                if ((pm >> i) & 1):
                    opens[2 * i + 1] = 1
            if closed:
                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: Wrong Answer

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

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**8)
for p in product([0, 1], repeat = 10):
    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: Wrong Answer

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

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

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

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 = min(set(sum(P, [])))
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: Wrong Answer

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

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

Submission status: Wrong Answer

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))
bit.pop(0)
ans = -float('inf')
for i in range(2 ** 10 - 2):
    memo = 0
    for j in range(n):
        cnt = 0
        for k in range(10):
            if bit[i][k] == f[j][k] == 1:
                cnt += 1
        memo += p[j][cnt]
    ans = max(ans, memo)
print(ans)

Submission status: Wrong Answer

Solution code:
#Forestの
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 ** 7
for i in range(1, 2 ** 10):
    cnt = [0] * n
    calc = 0
    #print(cnt)
    for j in range(10):
        if i >> j & 1:
            for k in range(n):
                if f[k][j] == 1:
                    cnt[k] += 1
    
                
    for k in range(n):
        calc += p[k][cnt[k]] 
    
    ans = max(ans, calc)

print(ans)

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

print(ans)

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 = -10 ** 7
for i in range(1, 2 ** 10):
    calc = 0
    for j in range(n):
        cnt = 0
        for k in range(10):
            if i >> k & 1 and f[j][k] == 1:
                cnt += 1
        calc += p[j][cnt]
                
    ans = max(ans, calc)

print(ans)

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

print(ans)