結果

問題 No.733 分身並列コーディング
コンテスト
ユーザー norioc
提出日時 2026-08-26 09:46:57
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
MLE  
実行時間 -
コード長 790 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 252 ms
コンパイル使用メモリ 96,224 KB
実行使用メモリ 1,093,188 KB
最終ジャッジ日時 2026-08-26 09:47:05
合計ジャッジ時間 5,383 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other MLE * 1 -- * 45
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from functools import cache


@cache
def bit_subsets(bit: int) -> list[int]:
    res = []
    b = bit
    while b:
        res.append(b)
        b = (b - 1) & bit

    return res


T = int(input())
N = int(input())

tasks = []
for i in range(N):
    tasks.append(int(input()))

b2sum = [0] * (1 << N)
for i in range(1 << N):
    t = 0
    for j in range(N):
        if i & (1 << j):
            t += tasks[j]

    b2sum[i] = t

full = (1 << N) - 1
dp = [False] * (1 << N)
dp[0] = True
for i in range(N):
    pp = dp.copy()
    dp, pp = pp, dp

    for b in range(1 << N):
        if not pp[b]: continue

        cb = full - b  # 補集合
        for sb in bit_subsets(cb):
            if b2sum[sb] <= T:
                dp[sb | b] = True

    if dp[full]:
        print(i+1)
        break
0