結果

問題 No.1701 half price
ユーザー 👑 H20H20
提出日時 2021-10-08 22:47:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 355 ms / 3,000 ms
コード長 612 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 87,104 KB
実行使用メモリ 77,480 KB
最終ジャッジ日時 2023-09-30 11:54:43
合計ジャッジ時間 3,977 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,344 KB
testcase_01 AC 73 ms
71,380 KB
testcase_02 AC 110 ms
77,236 KB
testcase_03 AC 75 ms
71,296 KB
testcase_04 AC 111 ms
77,204 KB
testcase_05 AC 80 ms
76,596 KB
testcase_06 AC 332 ms
77,480 KB
testcase_07 AC 355 ms
77,212 KB
testcase_08 AC 73 ms
71,404 KB
testcase_09 AC 74 ms
71,592 KB
testcase_10 AC 70 ms
71,356 KB
testcase_11 AC 73 ms
71,504 KB
testcase_12 AC 73 ms
71,420 KB
testcase_13 AC 73 ms
71,500 KB
testcase_14 AC 73 ms
71,492 KB
testcase_15 AC 73 ms
71,176 KB
testcase_16 AC 73 ms
71,372 KB
testcase_17 AC 164 ms
77,324 KB
testcase_18 AC 82 ms
76,592 KB
testcase_19 AC 87 ms
76,568 KB
testcase_20 AC 73 ms
71,432 KB
testcase_21 AC 331 ms
77,236 KB
権限があれば一括ダウンロードができます

ソースコード

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