結果

問題 No.1701 half price
ユーザー mink1618033mink1618033
提出日時 2021-10-08 23:12:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,144 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 77,884 KB
最終ジャッジ日時 2023-09-30 12:54:34
合計ジャッジ時間 3,518 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,140 KB
testcase_01 AC 73 ms
71,420 KB
testcase_02 AC 113 ms
77,756 KB
testcase_03 AC 72 ms
71,608 KB
testcase_04 AC 117 ms
77,560 KB
testcase_05 AC 77 ms
75,784 KB
testcase_06 AC 132 ms
77,548 KB
testcase_07 AC 146 ms
77,856 KB
testcase_08 WA -
testcase_09 AC 72 ms
71,532 KB
testcase_10 AC 74 ms
71,552 KB
testcase_11 AC 76 ms
71,340 KB
testcase_12 AC 73 ms
71,452 KB
testcase_13 AC 73 ms
71,264 KB
testcase_14 AC 76 ms
71,276 KB
testcase_15 AC 76 ms
71,332 KB
testcase_16 AC 72 ms
71,140 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 71 ms
71,340 KB
testcase_21 AC 146 ms
77,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import bisect
n,w = map(int,input().split())
a = list(map(int,input().split()))
a2 = [i//2 for i in a]
cnt=0          
s = set(range(n))

for bit in range(1<<n):
    li = []
    for j in range(n):
        if (bit>>j)&1==1:
            li.append(j)
    l = len(li)
    if l==1:
        if a[li[0]]==w or a2[li[0]]==w:
            cnt+=1
        continue
    if l==0:
        if w==0:
            cnt+=1
        continue
    cri = l//2
    ll1 = []
    for j in range(1<<cri):
        ka = 0
        for k in range(cri):
            if (j>>k)&1==1:
                ka+= a2[li[k]]
            else:
                ka+= a[li[k]]
        ll1.append(ka)
    ll1.sort()

    ll2 = []
    for j in range(1<<(l-cri)):
        ka = 0
        for k in range(l-cri):
            if (j>>k)&1==1:
                ka+= a2[li[-1-k]]
            else:
                ka+= a[li[-1-k]]
        ll2.append(ka)
    ll2.sort()
    #print(li,":",ll1,ll2)
    for i in ll1:
        if i>w:
            continue
        ind = bisect.bisect(ll2,w-i)
        #print(ind,ll2[ind-1])
        if ll2[ind-1]==w-i:
            cnt+=1
            break
print(cnt)
0