結果
| 問題 | No.15 カタログショッピング |
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 21:04:51 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 113 ms / 5,000 ms |
| コード長 | 1,463 bytes |
| 記録 | |
| コンパイル時間 | 222 ms |
| コンパイル使用メモリ | 96,112 KB |
| 実行使用メモリ | 96,716 KB |
| 最終ジャッジ日時 | 2026-07-07 12:45:10 |
| 合計ジャッジ時間 | 2,186 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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()
lam6er