結果

問題 No.15 カタログショッピング
ユーザー TawaraTawara
提出日時 2016-07-29 01:25:39
言語 Python2
(2.7.18)
結果
AC  
実行時間 396 ms / 5,000 ms
コード長 519 bytes
コンパイル時間 478 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 38,576 KB
最終ジャッジ日時 2024-04-24 10:40:28
合計ジャッジ時間 3,069 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,656 KB
testcase_01 AC 11 ms
6,656 KB
testcase_02 AC 11 ms
6,656 KB
testcase_03 AC 12 ms
6,784 KB
testcase_04 AC 10 ms
6,784 KB
testcase_05 AC 387 ms
38,576 KB
testcase_06 AC 387 ms
38,448 KB
testcase_07 AC 396 ms
38,444 KB
testcase_08 AC 378 ms
38,412 KB
testcase_09 AC 384 ms
38,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
XR = xrange;
N,S = map(int,raw_input().split())
P = [int(raw_input()) for i in XR(N)]
def enum(n,ofs):
	L = defaultdict(list)
	dp = [0]*(1<<n)
	for i in XR(1<<n):
		L[dp[i]].append(i)
		for j in XR(n): 
			if i & (1<<j): continue
			dp[i|(1<<j)] = dp[i] + P[j+ofs]
	return L
H = N/2
L1,L2 = enum(H,0),enum(N-H,H)
ans = []
for v,l in L1.iteritems():
	ans.extend([i+1 for i in XR(N) if(1<<i)&(b1+(b2<<H))] for b1 in l for b2 in L2[S-v])
for a in sorted(ans): print " ".join(map(str,a))
0