結果

問題 No.15 カタログショッピング
ユーザー pluto77
提出日時 2018-07-29 08:52:22
言語 Python2
(2.7.18)
結果
AC  
実行時間 225 ms / 5,000 ms
コード長 581 bytes
コンパイル時間 42 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 30,284 KB
最終ジャッジ日時 2024-07-08 05:54:43
合計ジャッジ時間 1,998 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#yuki15
from collections import defaultdict as dd
from itertools import combinations as comb

n,s=map(int,raw_input().split())
p=[]
for i in xrange(n):
 p.append(int(raw_input()))

res=[]
dic=dd(list)
for i in xrange(1,n/2+1):
 for s1 in comb(range(n/2),i):
  t=sum(p[j] for j in s1)
  if t==s:
   res.append(s1)
  dic[t].append(s1)
for i in xrange(1,n-n/2+1):
 for s2 in comb(range(n/2,n),i):
  t=sum(p[j] for j in s2)
  if t==s:
   res.append(s2)
  for s1 in dic[s-t]:
   res.append(s1+s2)
res=[[i+1 for i in s] for s in res]
res.sort()
for s in res:
 print " ".join(map(str,s))
0