結果

問題 No.5 数字のブロック
ユーザー warashi
提出日時 2015-02-12 17:42:11
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 520 bytes
コンパイル時間 503 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 270,968 KB
最終ジャッジ日時 2024-06-23 19:07:24
合計ジャッジ時間 7,080 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 TLE * 1 -- * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
from functools import lru_cache


@lru_cache(maxsize=None)
def box_in(L, W):
    W = list(W)
    for w in W:
        if w > L:
            W.remove(w)
    if len(W) == 0:
        return 0

    candidate = []
    for w in W:
        Wtmp = list(W)
        Wtmp.remove(w)
        candidate.append(box_in(L - w, tuple(Wtmp)))
    if len(candidate) == 0:
        return 1
    return max(candidate) + 1
L = int(input())
N = int(input())
W = sorted(map(int, input().split()))
print(box_in(L, tuple(W)))
0