結果

問題 No.15 カタログショッピング
ユーザー ayaoniayaoni
提出日時 2020-12-04 11:55:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 184 ms / 5,000 ms
コード長 1,049 bytes
コンパイル時間 550 ms
コンパイル使用メモリ 86,932 KB
実行使用メモリ 100,100 KB
最終ジャッジ日時 2023-10-13 00:13:51
合計ジャッジ時間 2,594 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
71,608 KB
testcase_01 AC 96 ms
71,508 KB
testcase_02 AC 100 ms
71,436 KB
testcase_03 AC 107 ms
77,548 KB
testcase_04 AC 100 ms
71,452 KB
testcase_05 AC 167 ms
92,288 KB
testcase_06 AC 177 ms
100,100 KB
testcase_07 AC 168 ms
92,260 KB
testcase_08 AC 184 ms
99,972 KB
testcase_09 AC 166 ms
92,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


N,S = MI()
P = [I() for _ in range(N)]

P0,P1 = P[:N//2],P[N//2:]
N0,N1 = len(P0),len(P1)

dic_P1 = defaultdict(list)
for i in range(1<<N1):
    s = 0
    for j in range(N1):
        if (i>>j) & 1:
            s += P1[N1-1-j]
    dic_P1[s].append(i)

ANS = []
for i in range(1<<N0):
    s = 0
    for j in range(N0):
        if (i>>j) & 1:
            s += P0[N0-1-j]
    if dic_P1[S-s]:
        for k in dic_P1[S-s]:
            ANS.append((i<<N1)+k)

ANS.sort(reverse=True)
for ans in ANS:
    X = [i+1 for i in range(N) if (ans >> (N-1-i)) & 1]
    print(*X)
0