結果

問題 No.15 カタログショッピング
ユーザー TawaraTawara
提出日時 2016-07-29 00:51:16
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 525 bytes
コンパイル時間 613 ms
コンパイル使用メモリ 6,696 KB
実行使用メモリ 38,088 KB
最終ジャッジ日時 2023-08-06 15:13:22
合計ジャッジ時間 4,129 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,308 KB
testcase_01 AC 13 ms
6,240 KB
testcase_02 AC 13 ms
6,468 KB
testcase_03 AC 14 ms
6,444 KB
testcase_04 AC 13 ms
6,244 KB
testcase_05 AC 434 ms
38,004 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