結果

問題 No.914 Omiyage
コンテスト
ユーザー nadare
提出日時 2019-10-25 21:32:40
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 613 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,106 ms
コンパイル使用メモリ 84,280 KB
実行使用メモリ 88,992 KB
最終ジャッジ日時 2026-04-11 19:40:01
合計ジャッジ時間 2,874 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# -*- 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