結果

問題 No.15 カタログショッピング
ユーザー roiti46roiti46
提出日時 2015-10-11 07:09:46
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 711 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 6,764 KB
実行使用メモリ 31,412 KB
最終ジャッジ日時 2023-09-28 11:39:38
合計ジャッジ時間 2,255 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

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

ans = []
dic = coll.defaultdict(list)
for i in xrange(1, N / 2 + 1):
    for s1 in it.combinations(range(N / 2), i):
        T = sum(P[j] for j in s1)
        if T == S: ans.append(s1)
        dic[T].append(s1)

for i in xrange(1, N / 2 + 1):
    for s2 in it.combinations(range(N / 2, N), i):
        T = sum(P[j] for j in s2)
        if T == S: ans.append(s2)
        for s1 in dic[S - T]:
            ans.append(s1 + s2)

ans = [[i + 1 for i in s] for s in ans]
ans.sort()
for line in s:
    print " ".join(map(str, s))
0