結果

問題 No.15 カタログショッピング
ユーザー kimiyukikimiyuki
提出日時 2017-01-08 14:39:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,013 bytes
コンパイル時間 1,227 ms
コンパイル使用メモリ 90,416 KB
実行使用メモリ 7,484 KB
最終ジャッジ日時 2023-08-22 17:36:17
合計ジャッジ時間 18,921 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using ll = long long;
using namespace std;
int main() {
    int n; ll s; cin >> n >> s;
    vector<ll> p(n); repeat (i,n) cin >> p[i];
    vector<ll> acc { 0 }; whole(partial_sum, p, back_inserter(acc));
    vector<vector<int> > result;
    vector<int> path;
    function<void (int, ll)> go = [&](int i, ll q) {
        if (q == s) result.push_back(path);
        if (q >= s) return;
        if (q + acc[n] - acc[i] < s) return;
        if (i == n) return;
        go(i+1, q);
        path.push_back(i);
        go(i+1, q + p[i]);
        path.pop_back();
    };
    go(0, 0);
    whole(sort, result);
    for (auto path : result) {
        repeat (i,path.size()) cout << (i ? " " : "") << path[i]+1;
        cout << endl;
    }
    return 0;
}
0