結果
問題 | No.15 カタログショッピング |
ユーザー |
![]() |
提出日時 | 2025-03-20 21:04:51 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 120 ms / 5,000 ms |
コード長 | 1,463 bytes |
コンパイル時間 | 146 ms |
コンパイル使用メモリ | 82,840 KB |
実行使用メモリ | 87,556 KB |
最終ジャッジ日時 | 2025-03-20 21:05:07 |
合計ジャッジ時間 | 1,605 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
import sys from collections import defaultdict def main(): input = sys.stdin.read().split() idx = 0 N = int(input[idx]) idx += 1 S = int(input[idx]) idx += 1 P = [] for _ in range(N): P.append(int(input[idx])) idx += 1 split_at = N // 2 a_size = split_at b_size = N - split_at # Precompute all subsets of the first half a_subsets = defaultdict(list) for mask in range(0, 1 << a_size): total = 0 items = [] for i in range(a_size): if mask & (1 << i): total += P[i] items.append(i + 1) # 1-based index a_subsets[total].append(items) solutions = [] # Process all subsets of the second half for mask in range(0, 1 << b_size): total_b = 0 items_b = [] for j in range(b_size): if mask & (1 << j): total_b += P[split_at + j] items_b.append((split_at + j) + 1) # 1-based index remaining = S - total_b if remaining in a_subsets: for a_items in a_subsets[remaining]: combined = a_items + items_b if combined: # ensure at least one item is selected solutions.append(combined) # Sort the solutions lexicographically solutions = sorted(solutions) for sol in solutions: print(' '.join(map(str, sol))) if __name__ == '__main__': main()