結果

問題 No.914 Omiyage
ユーザー brthyyjpbrthyyjp
提出日時 2020-03-17 01:38:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 625 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 85,732 KB
最終ジャッジ日時 2023-08-19 06:48:37
合計ジャッジ時間 4,151 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
85,732 KB
testcase_01 AC 155 ms
85,488 KB
testcase_02 AC 121 ms
85,576 KB
testcase_03 AC 139 ms
85,640 KB
testcase_04 AC 121 ms
85,644 KB
testcase_05 AC 67 ms
71,348 KB
testcase_06 AC 66 ms
71,668 KB
testcase_07 AC 68 ms
71,364 KB
testcase_08 AC 66 ms
71,404 KB
testcase_09 AC 67 ms
71,684 KB
testcase_10 AC 68 ms
71,408 KB
testcase_11 AC 66 ms
71,268 KB
testcase_12 AC 84 ms
76,572 KB
testcase_13 AC 137 ms
85,376 KB
testcase_14 AC 138 ms
85,600 KB
testcase_15 AC 66 ms
71,448 KB
testcase_16 AC 64 ms
71,276 KB
testcase_17 AC 77 ms
76,736 KB
testcase_18 AC 65 ms
71,524 KB
testcase_19 AC 66 ms
71,232 KB
testcase_20 AC 64 ms
71,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

p = n//2
B = []

import itertools
for i in itertools.product(range(m), repeat=p):
    b = 0
    for j in range(p):
        b += A[j][i[j]]
    B.append(b)
#print(B)

C = []
for i in itertools.product(range(m), repeat=n-p):
    c = 0
    for j in range(p, n):
        c += A[j][i[j-p]]
    C.append(c)
#print(C)

import bisect
B.sort()
C.sort()
id = 0
ans = k
for b in B:
    id = bisect.bisect_right(C, k-b)
    if id == 0:
        break
    else:
        ans = min(ans, k-b-C[id-1])
if ans == k:
    print(-1)
else:
    print(ans)
0