結果
問題 |
No.15 カタログショッピング
|
ユーザー |
|
提出日時 | 2015-10-11 07:11:30 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 250 ms / 5,000 ms |
コード長 | 714 bytes |
コンパイル時間 | 96 ms |
コンパイル使用メモリ | 7,072 KB |
実行使用メモリ | 31,848 KB |
最終ジャッジ日時 | 2024-07-21 06:20:37 |
合計ジャッジ時間 | 2,036 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
# -*- 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 - 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 s in ans: print " ".join(map(str, s))