結果

問題 No.15 カタログショッピング
ユーザー TawaraTawara
提出日時 2016-07-29 00:51:16
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 525 bytes
コンパイル時間 253 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 38,480 KB
最終ジャッジ日時 2024-04-24 10:39:51
合計ジャッジ時間 3,141 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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): 
			jbit = 1<<j
			if i & jbit: continue
			dp[i|jbit] = dp[i] + P[j+ofs]
	return L
H = N/2
L1 = enum(H,0)
L2 = enum(N-H,H)
ans = []
for v,l in L1.iteritems():
	ans.extend(" ".join(str(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 a
0