結果

問題 No.15 カタログショッピング
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-04-14 11:18:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 804 bytes
コンパイル時間 594 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 92,412 KB
最終ジャッジ日時 2023-09-13 01:15:46
合計ジャッジ時間 2,129 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,524 KB
testcase_01 AC 72 ms
71,320 KB
testcase_02 AC 72 ms
71,296 KB
testcase_03 AC 77 ms
76,524 KB
testcase_04 AC 69 ms
71,356 KB
testcase_05 AC 119 ms
86,632 KB
testcase_06 AC 130 ms
91,952 KB
testcase_07 AC 130 ms
92,412 KB
testcase_08 AC 134 ms
91,988 KB
testcase_09 AC 132 ms
92,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,s = map(int,input().split())
P = [int(input()) for i in range(n)]

lsize = n//2
lP = P[:lsize]
rsize = n-lsize
rP = P[lsize:]

dic = {}
for i in range(1<<rsize):
    count = 0
    for j in range(rsize)[::-1]:
        if i >> j & 1:
            count += rP[rsize-1-j]
    if count <= s:
        if count in dic:
            dic[count].append(i)
        else:
            dic[count] = [i]

ans = []

for i in range(1<<lsize):
    count = 0
    for j in range(lsize)[::-1]:
        if i >> j & 1:
            count += lP[lsize-1-j]
    if count <= s:
        if s-count in dic:
            for j in dic[s-count]:
                ans.append((i<<rsize)+j)

ans.sort(reverse=True)

for i in ans:
    cand = []
    for j in range(n)[::-1]:
        if i >> j & 1:
            cand.append(n-j)
    print(*cand)
0