結果

問題 No.15 カタログショッピング
ユーザー tnodinotnodino
提出日時 2022-02-06 18:14:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 423 ms / 5,000 ms
コード長 816 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 10,852 KB
実行使用メモリ 46,392 KB
最終ジャッジ日時 2023-09-02 07:04:30
合計ジャッジ時間 3,447 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,576 KB
testcase_01 AC 19 ms
8,552 KB
testcase_02 AC 19 ms
8,472 KB
testcase_03 AC 19 ms
8,600 KB
testcase_04 AC 19 ms
8,584 KB
testcase_05 AC 395 ms
46,320 KB
testcase_06 AC 409 ms
46,392 KB
testcase_07 AC 423 ms
46,372 KB
testcase_08 AC 413 ms
46,260 KB
testcase_09 AC 391 ms
46,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
def bitSearch(N, P):
    dic = defaultdict(list)
    for bit in range(1<<N):
        x = bit
        S = 0
        Set = []
        for i in range(N):
            if x & 1:
                S += P[i]
                Set.append(i+1)
            x >>= 1
        dic[S].append(Set)
    return dic

N,S = map(int,input().split())
LN = N // 2
RN = N - LN
L = [int(input()) for _ in range(LN)]
R = [int(input()) for _ in range(RN)]
Ldic = bitSearch(LN, L)
Rdic = bitSearch(RN, R)
ans = []
for Lkey in Ldic.keys():
    if Rdic[S-Lkey]:
        Rkey = S - Lkey
        for x in Ldic[Lkey]:
            for y in Rdic[Rkey]:
                Set = list(x)
                for k in y:
                    Set.append(k+LN)
                ans.append(Set)
ans.sort()
for x in ans:
    print(*x)
0