結果
問題 | No.15 カタログショッピング |
ユーザー |
|
提出日時 | 2017-01-08 14:44:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,402 ms / 5,000 ms |
コード長 | 1,179 bytes |
コンパイル時間 | 1,309 ms |
コンパイル使用メモリ | 94,152 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-17 18:03:21 |
合計ジャッジ時間 | 5,013 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
#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<int> tr(n); whole(iota, tr, 0);whole(sort, tr, [&](int i, int j) { return p[i] > p[j]; });vector<ll> acc(n+1); repeat (i,n) acc[i+1] = acc[i] + p[tr[i]];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(tr[i]);go(i+1, q + p[tr[i]]);path.pop_back();};go(0, 0);for (auto & path : result) whole(sort, path);whole(sort, result);for (auto & path : result) {repeat (i,path.size()) cout << (i ? " " : "") << path[i]+1;cout << endl;}return 0;}