結果
| 問題 |
No.15 カタログショッピング
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-10-11 07:09:46 |
| 言語 | Python2 (2.7.18) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 711 bytes |
| コンパイル時間 | 115 ms |
| コンパイル使用メモリ | 6,912 KB |
| 実行使用メモリ | 31,820 KB |
| 最終ジャッジ日時 | 2024-07-21 06:19:29 |
| 合計ジャッジ時間 | 1,594 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 9 RE * 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 line in s:
print " ".join(map(str, s))