結果

問題 No.15 カタログショッピング
ユーザー Ricky_ponRicky_pon
提出日時 2020-05-19 00:07:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 350 ms / 5,000 ms
コード長 1,719 bytes
コンパイル時間 2,606 ms
コンパイル使用メモリ 210,432 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-09 21:47:02
合計ジャッジ時間 3,727 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 25 ms
6,940 KB
testcase_06 AC 80 ms
6,940 KB
testcase_07 AC 187 ms
6,944 KB
testcase_08 AC 350 ms
6,940 KB
testcase_09 AC 225 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int n;
lint S;
pair<lint, int> p[35];
vector<vector<int>> ans;

void add(lint T){
    vector<int> v;
    rep(i, n)if(T>>i & 1) v.push_back(i+1);
    ans.push_back(v);
}

void dfs(int cur, lint T, lint sum, lint rest){
    if(sum == S){
        add(T);
        return;
    }
    if(cur == n) return;
    rest -= p[cur].fi;
    if(sum + p[cur].fi <= S){
        dfs(cur+1, T | (1LL<<p[cur].se), sum + p[cur].fi, rest);
    }
    if(sum + rest >= S){
        dfs(cur+1, T, sum, rest);
    }
}

int main(){
    scanf("%d%lld", &n, &S);
    lint rest = 0;
    rep(i, n){
        scanf("%lld", &p[i].fi);
        p[i].se = i;
        rest += p[i].fi;
    }
    sort(p, p+n, greater<>());
    dfs(0, 0, 0, rest);
    sort(ans.begin(), ans.end());
    for(auto &v: ans){
        for(int i: v) printf("%d ", i);
        printf("\n");
    }
}
0