結果

問題 No.15 カタログショッピング
ユーザー nsd_fbnsd_fb
提出日時 2015-02-20 09:35:56
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 527 bytes
コンパイル時間 41 ms
コンパイル使用メモリ 6,740 KB
実行使用メモリ 10,592 KB
最終ジャッジ日時 2023-09-06 02:27:09
合計ジャッジ時間 6,787 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,120 KB
testcase_01 AC 11 ms
6,200 KB
testcase_02 AC 12 ms
6,064 KB
testcase_03 AC 18 ms
6,168 KB
testcase_04 AC 11 ms
6,028 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def dfs(index, money, goods):
    if money == S:
        print ' '.join(goods)
        return

    if index == N or money > S or money + accumulation[index] < S:
        return

    goods.append(str(index + 1))
    dfs(index + 1, money + P[index], goods)
    goods.pop()
    dfs(index + 1, money, goods)


N, S = map(int, raw_input().split())
P = [input() for i in xrange(N)]

accumulation = [0] * N
accumulation[N - 1] = P[N - 1]
for i in xrange(N - 2, -1, -1):
    accumulation[i] = accumulation[i + 1] + P[i]

dfs(0, 0, [])
0