結果

問題 No.15 カタログショッピング
ユーザー nsd_fbnsd_fb
提出日時 2015-02-20 11:22:15
言語 Python2
(2.7.18)
結果
AC  
実行時間 277 ms / 5,000 ms
コード長 742 bytes
コンパイル時間 58 ms
コンパイル使用メモリ 6,696 KB
実行使用メモリ 45,576 KB
最終ジャッジ日時 2023-09-06 02:28:54
合計ジャッジ時間 2,138 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
5,880 KB
testcase_01 AC 11 ms
6,032 KB
testcase_02 AC 11 ms
6,008 KB
testcase_03 AC 11 ms
5,972 KB
testcase_04 AC 11 ms
6,040 KB
testcase_05 AC 277 ms
45,544 KB
testcase_06 AC 275 ms
45,576 KB
testcase_07 AC 272 ms
45,508 KB
testcase_08 AC 274 ms
45,408 KB
testcase_09 AC 276 ms
45,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def dfs(index, money, goods, dic, end):
    global P

    if index == end:
        dic.setdefault(money, []).append(list(goods))
        return

    goods.append(index + 1)
    dfs(index + 1, money + P[index], goods, dic, end)
    goods.pop()

    dfs(index + 1, money, goods, dic, end)

N, S = map(int, raw_input().split())
P = [int(raw_input()) for i in xrange(N)]

first = {}
second = {}
dfs(0, 0, [], first, N / 2)
dfs(N / 2, 0, [], second, N)

ans = []

for money, l in first.iteritems():
    if not S - money in second:
        continue

    for first_goods in l:
        for second_goods in second[S - money]:
                ans.append(first_goods + second_goods)
    
ans.sort()
for goods in ans:
    print ' '.join(map(str, goods))
0