結果

問題 No.914 Omiyage
ユーザー nadarenadare
提出日時 2019-10-25 21:32:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 613 bytes
コンパイル時間 1,028 ms
コンパイル使用メモリ 81,412 KB
実行使用メモリ 81,076 KB
最終ジャッジ日時 2023-10-24 21:11:50
合計ジャッジ時間 3,078 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
81,076 KB
testcase_01 AC 125 ms
81,076 KB
testcase_02 AC 87 ms
75,508 KB
testcase_03 AC 114 ms
81,076 KB
testcase_04 AC 87 ms
75,436 KB
testcase_05 AC 39 ms
53,336 KB
testcase_06 AC 39 ms
53,336 KB
testcase_07 AC 38 ms
53,336 KB
testcase_08 AC 38 ms
53,336 KB
testcase_09 AC 39 ms
53,336 KB
testcase_10 AC 39 ms
53,336 KB
testcase_11 AC 39 ms
53,336 KB
testcase_12 AC 57 ms
72,404 KB
testcase_13 AC 108 ms
80,284 KB
testcase_14 AC 114 ms
81,076 KB
testcase_15 AC 39 ms
53,336 KB
testcase_16 AC 39 ms
53,336 KB
testcase_17 AC 54 ms
68,236 KB
testcase_18 AC 39 ms
53,336 KB
testcase_19 AC 38 ms
53,336 KB
testcase_20 AC 39 ms
53,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
from itertools import product
from bisect import bisect
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

N, M, K = inpl()
A = [inpl() for _ in range(N)]
ans = -1
h = N//2

L = []
for J in product(range(M), repeat=h):
    tmp = 0
    for i, j in enumerate(J):
        tmp += A[i][j]
    if tmp <= K:
        L.append(tmp)

L = sorted(L)

for J in product(range(M), repeat=N-h):
    tmp = 0
    for i, j in enumerate(J):
        tmp += A[i+h][j]
    r = bisect(L, K-tmp)
    if r:
        ans = max(ans, tmp+L[r-1])

print(K-ans if ans >= 0 else -1)
0