結果

問題 No.15 カタログショッピング
ユーザー face4face4
提出日時 2018-11-04 18:16:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 535 bytes
コンパイル時間 812 ms
コンパイル使用メモリ 67,708 KB
実行使用メモリ 7,872 KB
最終ジャッジ日時 2023-08-13 03:25:11
合計ジャッジ時間 11,372 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3,977 ms
4,376 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

int p[32], sum[32] = {};
int n, s;

void dfs(int i, int a, string str){
    if(a == s){
        cout << str.substr(1) << endl;
        return;
    }

    if(i == n || a + sum[i] < s)  return;

    if(a + p[i] <= s)       dfs(i+1, a+p[i], str + " " + to_string(i+1));
    if(a + sum[i+1] >= s)   dfs(i+1, a, str);
}

int main(){
    cin >> n >> s;

    for(int i = 0; i < n; i++)  cin >> p[i];
    
    for(int i = 30; i >= 0; i--) sum[i] += sum[i+1] + p[i];

    dfs(0, 0, "");

    return 0;
}
0