結果

問題 No.15 カタログショッピング
ユーザー pluto77pluto77
提出日時 2018-07-29 08:52:22
言語 Python2
(2.7.18)
結果
AC  
実行時間 219 ms / 5,000 ms
コード長 581 bytes
コンパイル時間 45 ms
コンパイル使用メモリ 6,764 KB
実行使用メモリ 29,836 KB
最終ジャッジ日時 2023-09-22 14:18:45
合計ジャッジ時間 2,030 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,240 KB
testcase_01 AC 13 ms
6,296 KB
testcase_02 AC 13 ms
6,232 KB
testcase_03 AC 13 ms
6,428 KB
testcase_04 AC 12 ms
6,312 KB
testcase_05 AC 210 ms
29,824 KB
testcase_06 AC 207 ms
29,800 KB
testcase_07 AC 203 ms
29,720 KB
testcase_08 AC 219 ms
29,836 KB
testcase_09 AC 212 ms
29,756 KB
権限があれば一括ダウンロードができます

ソースコード

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