結果
| 問題 |
No.15 カタログショッピング
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-10-11 07:10:30 |
| 言語 | Python2 (2.7.18) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 710 bytes |
| コンパイル時間 | 69 ms |
| コンパイル使用メモリ | 6,784 KB |
| 実行使用メモリ | 31,820 KB |
| 最終ジャッジ日時 | 2024-07-21 06:19:31 |
| 合計ジャッジ時間 | 1,944 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 WA * 1 |
ソースコード
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll
N, S = map(int, raw_input().split())
P = [int(raw_input()) for i in xrange(N)]
ans = []
dic = coll.defaultdict(list)
for i in xrange(1, N / 2 + 1):
for s1 in it.combinations(range(N / 2), i):
T = sum(P[j] for j in s1)
if T == S: ans.append(s1)
dic[T].append(s1)
for i in xrange(1, N / 2 + 1):
for s2 in it.combinations(range(N / 2, N), i):
T = sum(P[j] for j in s2)
if T == S: ans.append(s2)
for s1 in dic[S - T]:
ans.append(s1 + s2)
ans = [[i + 1 for i in s] for s in ans]
ans.sort()
for s in ans:
print " ".join(map(str, s))