結果

問題 No.15 カタログショッピング
ユーザー しらっ亭しらっ亭
提出日時 2015-07-03 03:08:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 993 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 21,596 KB
最終ジャッジ日時 2023-09-22 05:52:21
合計ジャッジ時間 2,287 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,232 KB
testcase_01 AC 16 ms
8,224 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 17 ms
8,372 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect


def solve(N, S, P):
    h = len(P) // 2
    F = P[:h]
    L = P[h:]

    def listup(p):
        m = [0] * (1 << len(p))
        for i in range(1 << len(p)):
            s = 0
            for j in range(len(p)):
                if i & (1 << j):
                    s += p[j]
            m[i] = (s, i)
        return m

    fm = listup(F)
    lm = listup(L)

    lm.sort()

    ans = []

    for fi in range(1 << h):
        fp = fm[fi][0]
        lp = S - fp
        lil = bisect.bisect_left(lm, (lp, 0))
        lir = bisect.bisect_right(lm, (lp, S))
        for l in range(lil, lir):
            if l < len(lm) and lm[l][0] == lp:
                ans.append((l << h) | fi)

    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