結果

問題 No.1701 half price
ユーザー H20
提出日時 2021-10-08 22:47:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 323 ms / 3,000 ms
コード長 612 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 82,136 KB
実行使用メモリ 76,288 KB
最終ジャッジ日時 2024-07-23 05:54:30
合計ジャッジ時間 2,935 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

N,W = map(int,input().split())
A = list(map(int, input().split())) 
ans = 0
for i in range(2 ** N):
    bag = []
    total = 0
    for j in range(N):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            bag.append(A[j])
            total += A[j]
    ok = total==W
    for j in range(2 ** len(bag)):
        temp = 0
        for k in range(len(bag)):
            if ((j >> k) & 1):
                temp+=bag[k]//2
        ok = ok or (total - temp == W)
    if ok and len(bag):
        ans+=1
        print
print(ans)
0