結果

問題 No.15 カタログショッピング
ユーザー しらっ亭しらっ亭
提出日時 2015-07-03 02:32:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 647 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 10,868 KB
実行使用メモリ 11,280 KB
最終ジャッジ日時 2023-09-22 05:49:52
合計ジャッジ時間 6,903 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,772 KB
testcase_01 AC 16 ms
7,776 KB
testcase_02 AC 25 ms
8,384 KB
testcase_03 AC 117 ms
11,280 KB
testcase_04 AC 15 ms
7,764 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(N, S, P):
    memo = set()
    ans = []

    def memo_rec(b, r):
        if b in memo:
            return

        memo.add(b)

        if r == 0:
            ans.append(b)

        for i in range(N):
            i1 = 1 << i
            if b & i1 == 0 and r - P[i] >= 0:
                memo_rec(b | i1, r - P[i])

    memo_rec(0, S)

    ans = [[i + 1 for i in range(N) if a & (1 << i)] for a in ans]

    ans.sort()
    for a in ans:
        print(*a)


def main():
    N, S = list(map(int, input().split()))
    P = [0] * N
    for i in range(N):
        P[i] = int(input())
    solve(N, S, P)


if __name__ == '__main__':
    main()
0