結果

問題 No.15 カタログショッピング
ユーザー mkawa2mkawa2
提出日時 2021-12-08 10:44:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 167 ms / 5,000 ms
コード長 1,425 bytes
コンパイル時間 2,400 ms
コンパイル使用メモリ 86,756 KB
実行使用メモリ 106,220 KB
最終ジャッジ日時 2023-09-23 02:44:04
合計ジャッジ時間 2,693 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
71,324 KB
testcase_01 AC 95 ms
71,300 KB
testcase_02 AC 98 ms
71,324 KB
testcase_03 AC 99 ms
71,760 KB
testcase_04 AC 96 ms
71,452 KB
testcase_05 AC 165 ms
105,912 KB
testcase_06 AC 165 ms
106,220 KB
testcase_07 AC 167 ms
105,936 KB
testcase_08 AC 167 ms
106,192 KB
testcase_09 AC 165 ms
105,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = 18446744073709551615
inf = 4294967295
md = 10**9+7
# md = 998244353

from collections import defaultdict

def split_and_list(aa):
    bs = [(0, 0)]
    for i, a in enumerate(aa):
        nbs = []
        for b, s in bs:
            nb = b | 1 << i
            ns = s+a
            nbs.append((nb, ns))
        bs += nbs

    res = defaultdict(list)
    for b, s in bs: res[s].append(b)
    return res

n, S = LI()
n2 = n//2

pp = [II() for _ in range(n)]
pre = split_and_list(pp[:n2])
pos = split_and_list(pp[n2:])

bs = []
for s, bb in pre.items():
    for b0 in bb:
        for b1 in pos[S-s]:
            bs.append(b0 | b1 << n2)

ans = []
for b in bs:
    cur = [i+1 for i in range(n) if b >> i & 1]
    ans.append(cur)

ans.sort()
for cur in ans: print(*cur)
0