結果
問題 | No.15 カタログショッピング |
ユーザー | szkhts |
提出日時 | 2021-02-23 14:36:47 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 921 bytes |
コンパイル時間 | 144 ms |
コンパイル使用メモリ | 11,888 KB |
実行使用メモリ | 17,044 KB |
最終ジャッジ日時 | 2023-10-23 14:57:17 |
合計ジャッジ時間 | 3,570 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
ソースコード
N, S = map(int, input().split()) price = [int(input()) for _ in range(N)] price_A = {} a = N // 2 b = N - a for i in range(1 << a): sum = 0 for j in range(a): if (i >> j) % 2 == 0: continue sum += price[j] if sum in price_A: price_A[sum].append(i) else: price_A[sum] = [i] print(price_A) answer = [] for i in range(1 << b): sum = 0 for j in range(b): if (i >> j) % 2 == 0: continue sum += price[a + j] need = S - sum if need in price_A: for ar in price_A[need]: ans = [] for j in range(a): if (ar >> j) % 2 == 1: ans.append(j + 1) for j in range(b): if (i >> j) % 2 == 1: ans.append(a + j + 1) answer.append(ans) answer.sort() for ans in answer: print(' '.join(map(str, ans)))