結果

問題 No.1701 half price
コンテスト
ユーザー lam6er
提出日時 2025-03-31 18:00:44
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 48 ms / 3,000 ms
+ 997µs
コード長 640 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 96 ms
コンパイル使用メモリ 64,728 KB
実行使用メモリ 59,308 KB
最終ジャッジ日時 2026-10-15 02:53:00
合計ジャッジ時間 2,486 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

n, w = map(int, input().split())
a = list(map(int, input().split()))
b = [x // 2 for x in a]

answer = 0

for mask in range(1, 1 << n):
    s_b = []
    for i in range(n):
        if (mask >> i) & 1:
            s_b.append(b[i])
    sum_b = sum(s_b)
    required_T = w - sum_b
    if required_T < 0:
        continue
    
    # Generate all possible subset sums of s_b
    subset_sums = {0}
    for num in s_b:
        new_sums = set()
        for s in subset_sums:
            new_sum = s + num
            new_sums.add(new_sum)
        subset_sums.update(new_sums)
    
    if required_T in subset_sums:
        answer += 1

print(answer)
0