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 = [int(input().replace(" ", ""), 2) for _ in range(N)]
P = [list(map(int,input().split())) for _ in range(N)]
ans = 0

for i in range(1,1024):
    ans = max(ans, sum(P[n][bin(i & F[n]).count('1')]for n in range(N)))

print(ans)

Submission status: Wrong Answer

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

from itertools import product
ans = -float('inf')
for jo in product(range(2), repeat=10):
    prof = 0
    for p, f in zip(ps, fs):
        sim = sum(i * j for i, j in zip(jo, f))
        prof += p[sim]
    if prof > ans:
        ans = prof

print(ans)

Submission status: Wrong Answer

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

from itertools import product

def main():
    n = int(input())
    f = []
    p = []
    for ob in (f, p):
        for i in range(n):
            ro = list(map(int, input().split()))
            ob.append(ro)
    res = -999999999
    for open_at in product((0, 1), repeat=10):
        if 1 not in open_at:
            continue
        res = max(res, get_rieki(f, p, open_at, n))
    print(res)

def get_rieki(f, p, open_at, n):
    res = 0
    for i in range(n):
        cnt = 0
        for t in range(10):
            if f[i][t] == 1 and open_at[t] == 1:
                cnt += 1
        res += p[i][cnt]
    return res

main()

Submission status: Wrong Answer

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

maxt = None
for i in range(1, 2**10):
  total = 0
  for _f, _p in zip(f, p):
    c = 0
    for bi, fi in zip(bin(i)[2:], _f[::-1]):
      if fi==1 and int(bi)==1:
        c += 1
    total += _p[c]
  maxt = max(total, maxt) if maxt is not None else total
print(maxt)

Submission status: Wrong Answer

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

maxt = None
for i in range(1, 2**10):
  total = 0
  for _f, _p in zip(f, p):
    c = 0
    for bi, fi in zip(bin(i)[2:], _f):
      if fi==1 and int(bi)==1:
        c += 1
    total += _p[c]
  maxt = max(total, maxt) if maxt is not None else total
print(maxt)

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())))
MAX = -100000000
for j in range(1023):
    if j == 0:
        pass
    else:
        Fcount = [0 for a in range(N)]
        b = bin(j)
        blist = list(b)
        del blist[:2]
        L = len(blist)
        for k in range(10-L):
            blist.insert(0,"0")
        m = 0
        for m in range(10):
            if blist[m] == "1":
                o = 0
                for o in range(N):
                    if F[o][m] == 1:
                        Fcount[o]+=1
                    else:
                        pass
            else:
                pass
        kari = 0
        p = 0
        for p in range(N):
            kari+=P[p][Fcount[p]]
        if MAX <= kari and ("1" in blist):
            MAX = kari

print(MAX)

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())))
j = 1
MAX = -100000000
for j in range(1023):
    Fcount = [0 for a in range(N)]
    b = bin(j)
    blist = list(b)
    del blist[:2]
    L = len(blist)
    for k in range(10-L):
        blist.insert(0,"0")
    m = 0
    for m in range(10):
        if blist[m] == "1":
            o = 0
            for o in range(N):
                if F[o][m] == 1:
                    Fcount[o]+=1
                else:
                    pass
        else:
            pass
    kari = 0
    p = 0
    for p in range(N):
        kari+=P[p][Fcount[p]]
    if MAX <= kari and ("1" in blist):
        MAX = kari

print(MAX)

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())))
j = 1
MAX = -100000000
for j in range(1023):
    Fcount = [0 for a in range(N)]
    b = bin(j)
    blist = list(b)
    del blist[:2]
    L = len(blist)
    for k in range(10-L):
        blist.insert(0,"0")
    m = 0
    for m in range(10):
        if blist[m] == "1":
            o = 0
            for o in range(N):
                if F[o][m] == 1:
                    Fcount[o]+=1
                else:
                    pass
        else:
            pass
    kari = 0
    for p in range(N):
        kari+=P[p][Fcount[p]]
    if MAX <= kari and ("1" in blist):
        MAX = kari

print(MAX)

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())))
j = 1
MAX = -100000000
for j in range(1023):
    Fcount = [0 for a in range(N)]
    b = bin(j)
    blist = list(b)
    del blist[:2]
    L = len(blist)
    for k in range(10-L):
        blist.insert(0,"0")
    m = 0
    for m in range(10):
        if blist[m] == "1":
            o = 0
            for o in range(N):
                if F[o][m] == 1:
                    Fcount[o]+=1
                else:
                    pass
    kari = 0
    for p in range(N):
        kari+=P[p][Fcount[p]]
    if MAX <= kari and "1" in blist:
        MAX = kari

print(MAX)

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())))
j = 1
MAX = -100000000
for j in range(1023):
    Fcount = [0 for a in range(N)]
    b = bin(j)
    b.lstrip("0b")
    blist = list(b)
    L = len(blist)
    for k in range(10-L):
        blist.insert(0,"0")
    m = 0
    for m in range(10):
        if blist[m] == "1":
            o = 0
            for o in range(N):
                if F[o][m] == 1:
                    Fcount[o]+=1
                else:
                    pass
    kari = 0
    for p in range(N):
        kari+=P[p][Fcount[p]]
    if MAX <= kari:
        MAX = kari

print(MAX)

Submission status: Wrong Answer

Solution code:
N = int(input())

open = []
earn = []

for _ in range(N):
    open.append(list(map(int, input().split())))

for _ in range(N):
    earn.append(list(map(int, input().split())))


ans = -float('inf')
for i in range(1, 1 << 10):
    tmp = 0
    same = [0]*N
    for j in range(N):
        for k in range(10):
            if open[j][k] == (i & (1 << j)):
                same[j] += 1

    for j in range(N):
        tmp += earn[j][same[j]]
    ans = max(ans, tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

open = []
earn = []

for _ in range(N):
    open.append(list(map(int, input().split())))

for _ in range(N):
    earn.append(list(map(int, input().split())))


ans = -float('inf')
for i in range(1, 1 << N):
    tmp = 0
    same = [0]*N
    for j in range(N):
        for k in range(10):
            if open[j][k] == (i & (1 << j)):
                same[j] += 1

    for j in range(N):
        tmp += earn[j][same[j]]
    if tmp > 0:
        ans = max(ans, tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
F = [[int(i) for i in input().split()] for i in range(n)]
P = [[int(i) for i in input().split()] for i in range(n)]
A = [0] * 10

def f(x):
    if x % 2 == 0:
        return 1
    else:
        return 0
    
ans = -10 ** 10
for i in range(1, 2 ** 10):
    for j in range(10):
        A[j] = f(i // (2 ** (9 - j)))

    temp = 0
    for s in range(n):
        count = 0
        for t in range(10):
            if F[s][t] == 1 and A[t] == 1:
                count += 1
        temp += P[s][count]
    ans = max(ans, temp)
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
F = [[int(i) for i in input().split()] for i in range(n)]
P = [[int(i) for i in input().split()] for i in range(n)]
A = [0] * 10

def f(x):
    if x % 2 == 0:
        return 1
    else:
        return 0

ans = -10 ** 10
for i in range(1, 2 ** 10):
    for j in range(10):
        A[j] = f(i // (2 ** (9 - j)))

    temp = 0
    for s in range(n):
        count = 0
        for t in range(10):
            if F[s][t] == 1 and A[t] == 1:
                count += 1
        temp += P[s][count]
    ans = max(ans, temp)
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
F = [[int(i) for i in input().split()] for i in range(n)]
P = [[int(i) for i in input().split()] for i in range(n)]
A = [0] * 10

def f(x):
    if x % 2 == 0:
        return 1
    else:
        return 0
    
ans = -10 ** 10
for i in range(1, 2 ** 10):
    for j in range(10):
        A[j] = f(i // (2 ** (10 - i)))

    temp = 0
    for s in range(n):
        count = 0
        for t in range(10):
            if F[s][t] == 1 and A[t] == 1:
                count += 1
        temp += P[s][count]
    ans = max(ans, temp)
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
F = [[int(i) for i in input().split()] for i in range(n)]
P = [[int(i) for i in input().split()] for i in range(n)]

ans = -10 ** 10
for i in range(1, 2 ** 10):
    tmp = i
    A = []
    while tmp:
        A.append(tmp % 2)
        tmp //= 2
    while len(A) != 10:
        A.append(0)

    temp = 0
    for s in range(n):
        count = 0
        for t in range(10):
            if F[s][t] == 1 and A[t] == 1:
                count += 1
        temp += P[s][count]
        ans = max(ans, temp)
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
F = [[int(i) for i in input().split()] for i in range(n)]
P = [[int(i) for i in input().split()] for i in range(n)]

ans = -10 ** 7
for i in range(1, 2 ** 10):
    tmp = i
    A = []
    while tmp:
        A.append(tmp % 2)
        tmp //= 2
    while len(A) != 10:
        A.append(0)

    temp = 0
    for s in range(n):
        count = 0
        for t in range(10):
            if F[s][t] == 1 and A[t] == 1:
                count += 1
        temp += P[s][count]
        ans = max(ans, temp)
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
F = [[int(i) for i in input().split()] for i in range(n)]
P = [[int(i) for i in input().split()] for i in range(n)]
A = [0] * 10

def f(x):
    if x % 2 == 0:
        return 1
    else:
        return 0
    
for i in range(2 ** 10):
    for j in range(10):
        A[j] = f(i // (2 ** (9 - i)))

    ans = -10 ** 7
    for s in range(n):
        count = 0
        temp = 0
        for t in range(10):
            if F[s][t] == A[t] and A[t] == 1:
                count += 1
        temp += P[s][count]
        ans = max(ans, temp)
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
F = [[int(i) for i in input().split()] for i in range(n)]
P = [[int(i) for i in input().split()] for i in range(n)]
A = [0] * 10

def f(x):
    if x % 2 == 0:
        return 1
    else:
        return 0
    
for i in range(2 ** 10):
    for j in range(10):
        A[j] = f(i // (2 ** (9 - i)))

    ans = -10 ** 7
    for s in range(n):
        count = 0
        temp = 0
        for t in range(10):
            if F[s][t] == A[t]:
                count += 1
        temp += P[s][count]
        ans = max(ans, temp)
        
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

II = lambda: int(input())
MI = lambda: map(int, input().split())


def main():
    N = II()
    F = [tuple(MI()) for _ in range(N)]
    P = [tuple(MI()) for _ in range(N)]
    TS = 10

    answers = []
    for tt in range(1, 2**TS):
        ts_open = [False] * TS
        for i, c in enumerate(bin(tt)[2:]):
            ts_open[i] = (c == "1")
        a = 0
        for i in range(N):
            o = 0
            for j in range(TS):
                if ts_open[j] and F[i][j] == 1: o += 1
            a += P[i][o]
        answers.append(a)
    return max(answers)


if __name__ == "__main__":
    print(main())

Submission status: Wrong Answer

Solution code:
# coding: utf-8

II = lambda: int(input())
MI = lambda: map(int, input().split())


def main():
    N = II()
    F = [tuple(MI()) for _ in range(N)]
    P = [tuple(MI()) for _ in range(N)]
    TS = 10

    ans = int(-1e12)
    for tt in range(1, 2**TS):
        ts_open = [False] * TS
        for i, c in enumerate(bin(tt)[2:]):
            ts_open[i] = (c == "1")
        a = 0
        for i in range(N):
            o = 0
            for j in range(TS):
                if ts_open[j] and F[i][j] == 1: o += 1
            a += P[i][o]
        ans = max(ans, a)
    return ans


if __name__ == "__main__":
    print(main())

Submission status: Wrong Answer

Solution code:
# coding: utf-8

II = lambda: int(input())
MI = lambda: map(int, input().split())


def main():
    N = II()
    F = [tuple(MI()) for _ in range(N)]
    P = [tuple(MI()) for _ in range(N)]
    TS = 10

    ans = int(-1e12)
    for tt in range(1, 2**TS):
        ts_open = [False] * TS
        for i, c in enumerate(bin(tt)[2:]):
            ts_open[i] = (c == "1")
        a = 0
        for i in range(N):
            o = sum((ts_open[j] * F[i][j] for j in range(TS)))
            a += P[i][o]
        ans = max(ans, a)
    return ans


if __name__ == "__main__":
    print(main())

Submission status: Wrong Answer

Solution code:
# coding: utf-8

II = lambda: int(input())
MI = lambda: map(int, input().split())


def main():
    N = II()
    F = [tuple(MI()) for _ in range(N)]
    P = [tuple(MI()) for _ in range(N)]
    TS = 10

    ans = int(-1e8)
    for tt in range(1, 2**TS):
        ts_open = [False] * TS
        for i, c in enumerate(bin(tt)[2:]):
            ts_open[i] = (c == "1")
        a = 0
        for i in range(N):
            o = sum((ts_open[j] * F[i][j] for j in range(TS)))
            a += P[i][o]
        ans = max(ans, a)
    return ans


if __name__ == "__main__":
    print(main())

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

p0 = []
maxp = []
for i in range(n):
    p0.append(p[i][0])
    sumf = sum(f[i])
    maxp.append(max(p[i][1:(sumf+1)]))

cnt = 0
sum_max = []
for i in range(n):
    if p0[i] > maxp[i]:
        cnt += 1
    sum_max.append(max(p0[i],maxp[i]))
    
if cnt == n:
    a = []
    for i in range(n):
        a.append(p0[i] - maxp[i])
    print(sum(p0) - min(a))
else:
    print(sum(sum_max))

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

p0 = []
maxp = []
for i in range(n):
    p0.append(p[i][0])
    sumf = sum(f[i])
    maxp.append(max(p[i][1:(sumf+1)]))

cnt = 0
sum_max = []
for i in range(n):
    if p0[i] > maxp[i]:
        cnt += 1
    sum_max.append(max(p0[i],maxp[i]))

if cnt == n:
    a = []
    for i in range(n):
        a.append(sum(maxp))
        a.append(maxp[i] + sum(sum_max[:i]) + sum(sum_max[i+1:]))
    print(max(a))
else:
    print(sum(sum_max))

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

p0 = []
maxp = []
for i in range(n):
    p0.append(p[i][0])
    sumf = sum(f[i])
    maxp.append(max(p[i][1:(sumf+1)]))

a = []
for i in range(n):
    a.append(sum(maxp))
    a.append(p0[i] + sum(maxp[:i]) + sum(maxp[i+1:]))
print(max(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)]

p0 = []
maxp = []
for i in range(n):
    p0.append(p[i][0])
    sumf = sum(f[i])
    maxp.append(max(p[i][1:(sumf+1)]))
 
cnt = 0
sum_max = 0
for i in range(n):
    if p0[i] > maxp[i]:
        cnt += 1
    sum_max += max(p0[i],maxp[i])
 
if cnt == n:
    a = []
    for i in range(n):
        a.append(p0[i] + sum(maxp[:i]) + sum(maxp[i+1:]))
    print(max(a))
else:
    print(sum_max)

Submission status: Wrong Answer

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

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

res = -10**8
for b in range(1,2**10):
    bit = bin(b)[2:]
    bit = '0'*(10-len(bit))+bit
    tmp = 0
    for i in range(n):
        count = 0
        for j in range(10):
            if int(bit[j])==f[i][j]==1:
                count += 1
        tmp += p[i][count]
    res = max(res,tmp)
print(res)

Submission status: Wrong Answer

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

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

res = -10**7
for b in range(1,2**10):
    bit = bin(b)[2:]
    bit = '0'*(10-len(bit))+bit
    tmp = 0
    for i in range(n):
        count = 0
        for j in range(10):
            if int(bit[j])==f[i][j]==1:
                count += 1
        tmp += p[i][count]
    res = max(res,tmp)
print(res)

Submission status: Wrong Answer

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

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

res = -10**7
for b in range(1,2**11):
    bit = bin(b)[2:]
    bit = '0'*(10-len(bit))+bit
    tmp = 0
    for i in range(n):
        count = 0
        for j in range(10):
            if int(bit[j])==f[i][j]==1:
                count += 1
        tmp += p[i][count]
    res = max(res,tmp)
print(res)

Submission status: Wrong Answer

Solution code:
# ABC 080 
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0 for i in range(n)]

N = int(input())
F = []
for i in range(N):
    F.append(getIntList())
#print(F)#
P = []
for i in range(N):
    P.append(getIntList())
#print(P)#

maxProf = -10**8
for n in range(1,2**10):
    a = zeros(10)
    m = n
    for i in range(10):
        a[i] = m % 2
        m //= 2
    prof = 0
    for i in range(N):
        c = 0
        for j in range(10):
            c += a[j]*F[i][j]
        prof += P[i][c]
    if prof>maxProf: maxProf = prof
print(maxProf)

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

is_open=[]
def count_score(is_open,N,F,P):
    is_open_copy=list(is_open)
    if len(is_open_copy)==10:
        count_N = [0 for i in range(N)]
        for i in range(N):
            for j in range(10):
                if is_open[j] and F[i][j]==1:
                    count_N[i]+=1
        score = 0
        for i in range(N):
            score+=P[i][count_N[i]]
        return score
    return max(count_score(is_open_copy+[True],N,F,P),count_score(is_open_copy+[False],N,F,P))

print(count_score(is_open,N,F,P))

Submission status: Wrong Answer

Solution code:
ls = []
def onoff(n):
    global ls
    if len(n) == 10:
        ls.append(n)
    else:
        onoff(n + '0')
        onoff(n + '1')
onoff('1')
onoff('0')
n = int(input())
f = [list(map(str,input().split())) for x in range(n)]
p = [list(map(int,input().split())) for x in range(n)]
ans = -99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
for i in range(1024):
    check = 0
    for j in range(n):
        count = 0
        for k in range(10):
            if ls[i][k] == f[j][k] and ls[i][k] == '1':
                count += 1
        check += p[j][count]
    ans = max(ans,check)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
f = [int("".join(ls()), 2) for _ in range(n)]      
p = [list(li()) for _ in range(n)]

def dfs(cur:int, depth:int):
    if depth == 10:
        return sum([p[i][bin(cur&fi).count("1")] for i, fi in enumerate(f)])
    
    else:
        return max(dfs(cur+(1<<depth), depth+1),
                   dfs(cur, depth+1))
        
print(dfs(0,0))

Submission status: Wrong Answer

Solution code:

N = int(input())
farr = []
parr = []
for i in range(N):
    farr.append(list(map(int,input().split())))
for i in range(N):
    parr.append(list(map(int,input().split())))
paym = -10**10
count = 0
for i in range(1,1<<11):
    pay = 0
    for j in range(N):
        tmp = i
        for k in range(10):
            if farr[j][k] == 1 and (tmp//2**k)%2 == 1:
                count += 1
            if tmp == 0:
                break
        pay += parr[j][count]
        count = 0
        
    if pay > paym:
        paym = pay

print(paym)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    fs = [sum(map(int, input().split())) for _ in range(n)]
    pss = [list(map(int, input().split())) for _ in range(n)]

    table = []
    for i, f in enumerate(fs):
        ps = sorted(((p, bool(j))
                     for j, p in enumerate(pss[i][:f + 1])), reverse=True)
        table.append(ps[:2])

    p = sum(row[0][0] for row in table)
    if any(row[0][1] for row in table):
        print(p)
        return

    sub_min = table[0][0][0] - table[0][1][0]
    sub_min_i = 0
    for row in table[1:]:
        sub = row[0][0] - row[1][0]
        if sub < sub_min:
            sub_min = sub
            sub_min_i = i
    print(p - sub_min)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
f_list = []
p_list = []
max_list = []
semi_max_list= []
for i in range(n):
    _list = list(map(int, input().split()))
    f_list.append(_list)
for i in range(n):
    _list = list(map(int, input().split()))
    p_list.append(_list)
ans = 0
fine = 0
for i in range(n):
    count = 0
    for j in range(10):
        if f_list[i][j] == 1:
            count += 1
    max_ = -1000000000000000000
    del p_list[i][count+1:]
    max_ = max(p_list[i])
    if max_ == p_list[i][0]:
        fine += 1
    max_list.append(max_)
    p_list[i].remove(max_)
    semi_max_ = max(p_list[i])
    semi_max_list.append(semi_max_)
for i in max_list:
    ans += i
if fine != n:
    print(ans)
else:
    m_list = []
    for i in range(n):
        m_list.append(max_list[i] - semi_max_list[i])
    print(ans-min(m_list))

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())))
f_count = []
for i in f:
    f_count.append(i.count(1))
flag = 1
ans = 0
for i in range(n):
    if p[i][0:f_count[i]+1].index(max(p[i][0:f_count[i]+1])) != 0:
        flag = 0
if flag:
    check = []
    for i in range(n):
        check.append(p[i][1:f_count[i]+1])
        check_index = check.index(max(check))
    for i in range(n):
        if i == check_index:
            ans += max(p[i][1:f_count[i]+1])
        else:
            ans += p[i][0]
else:
    for i in range(n):
        ans += max(p[i][0:f_count[i]+1])
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())))
f_count = []
for i in f:
    f_count.append(i.count(1))
flag = 1
ans = 0
for i in range(n):
    if p[i][0:f_count[i]+1].index(max(p[i][0:f_count[i]+1])) != 0:
        flag = 0
if flag:
    check = []
    for i in range(n):
        check.append(p[i][1])
        check_index = check.index(max(check))
    for i in range(n):
        if i == check_index:
            ans += p[i][1]
        else:
            ans += p[i][0]
else:
    for i in range(n):
        ans += max(p[i][0:f_count[i]+1])
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product
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 v in product([0, 1], repeat=10):
    if v.count(1) == 0:
        continue
    tmp = 0
    for i in range(n):
        c = 0
        for j in range(10):
            if v[j] == 1 and f[i][j] == 1:
                c += 1
        tmp += p[i][c]
    ans = max(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
F = []
P = []
for i in range(N):
    temp = [int(i) for i in input().split()]
    tt = 0b0
    for j in range(len(temp)):
        tt += 2 ** j * temp[j]
    print(bin(tt))
    F.append(tt)
    
for i in range(N):
    temp = [int(i) for i in input().split()]
    P.append(temp)

def bene(bit):
    res = 0
    for i in range(N):
        a = bit & F[i]
        cc = 0
        for j in str(bin(a)):
            if j == "1":
                cc += 1
        res += P[i][cc]
    return res

benes = [bene(i) for i in range(1,1024)]
benes.sort()
print(benes[-1])

Submission status: Wrong Answer

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

ans = - 10 ** 10
for i in range(1, 2 ** 10 - 1):
    ans = max(ans, sum([P[j][bin(i&F[j]).count('1')] for j in range(N)]))
print(ans)

Submission status: Wrong Answer

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

ans = - 10 ** 9
for i in range(1, 2 ** 10 - 1):
    ans = max(ans, sum([P[j][bin(i&F[j]).count('1')] for j in range(N)]))
print(ans)

Submission status: Wrong Answer

Solution code:
a = int(input())
ar = []
br = []
count = 0
for i in range(a):
    l = input().split(" ")
    ar.append(l)
for j in range(a):
    m = list(map(int,input().split(" ")))
    br.append(m)
max = 0
for n,r in enumerate(ar):
    for k in range(r.count("1")+1):
        if max < br[n][k]:
            max = br[n][k]
    count += max
    max = 0
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
f = [[0 for j in range(10)] for i in range(n)]
p = [[0 for i in range(11)] for j in range(n)]
for i in range(n):
    f[i] = [int(i) for i in input().split()]
for i in range(n):
    p[i] = [int(i) for i in input().split()]

totalProfit = -100000000
N = [i for i in range(10)]  # N = bit探索する桁数
for i in range(1, 1 << len(N)):
    output = []
    for j in range(len(N)):
        if ((i >> j) & 1) == 1:
            output.append(j)  # このjが今回探索するindexの1つ
    profit = 0
    for j in range(n):
        sameOpen = 0
        for k in output:
            if f[j][k] == 1:  # 店j,曜日時間帯kと営業日被り
                sameOpen += 1
        profit += p[j][sameOpen]
        # print("store:{} sameOpen:{}".format(j, sameOpen))
    # print("profit:{} {}".format(profit, output))
    totalProfit = max(totalProfit, profit)
print(totalProfit)

Submission status: Wrong Answer

Solution code:
n = int(input())
f = [[0 for j in range(10)] for i in range(n)]
p = [[0 for i in range(11)] for j in range(n)]
for i in range(n):
    f[i] = [int(i) for i in input().split()]
for i in range(n):
    p[i] = [int(i) for i in input().split()]

totalProfit = -1000000
N = [i for i in range(10)]  # N = bit探索する桁数
for i in range(1, 1 << len(N)):
    output = []
    for j in range(len(N)):
        if ((i >> j) & 1) == 1:
            output.append(j)  # このjが今回探索するindexの1つ
    profit = 0
    for j in range(n):
        sameOpen = 0
        for k in output:
            if f[j][k] == 1:  # 店j,曜日時間帯kと営業日被り
                sameOpen += 1
        profit += p[j][sameOpen]
    # print("profit:{} {}".format(profit, output))
    totalProfit = max(totalProfit, profit)
print(totalProfit)

Submission status: Wrong Answer

Solution code:
n = int(input())
f = [[0 for j in range(10)] for i in range(n)]
p = [[0 for i in range(10)] for j in range(n)]
for i in range(n):
    f[i] = [int(i) for i in input().split()]
for i in range(n):
    p[i] = [int(i) for i in input().split()]

totalProfit = -1000000
N = [i for i in range(10)]  # N = bit探索する桁数
for i in range(1, 1 << len(N)):
    output = []
    for j in range(len(N)):
        if ((i >> j) & 1) == 1:
            output.append(j)  # このjが今回探索するindexの1つ
    profit = 0
    for j in range(n):
        sameOpen = 0
        for k in output:
            if f[j][k] == 1:  # 店j,曜日時間帯kと営業日被り
                sameOpen += 1
        profit += p[j][sameOpen]
    # print("profit:{} {}".format(profit, output))
    totalProfit = max(totalProfit, profit)
print(totalProfit)