結果

問題 No.15 カタログショッピング
ユーザー yogi_cgyogi_cg
提出日時 2020-03-30 16:42:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 2,288 bytes
コンパイル時間 3,544 ms
コンパイル使用メモリ 184,548 KB
実行使用メモリ 4,692 KB
最終ジャッジ日時 2023-09-03 21:02:07
合計ジャッジ時間 2,808 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h> 

#define int long long
#define double long double

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N, S; cin >> N >> S;
    vi P(N); REP(i, N) cin >> P[i];
    vpi X, Y;
    REP(i, 1 << N/2)
    {
        int sum = 0;
        REP(j, N/2)
        {
            if(i & (1 << j)) sum += P[j];
        }
        X.push_back(mp(sum, i));
    }
    REP(i, 1 << (N+1)/2)
    {
        int sum = 0;
        REP(j, (N+1)/2)
        {
            if(i & (1 << j)) sum += P[j+N/2];
        }
        Y.push_back(mp(sum, i));
    }
    sort(ALL(Y));

    #ifdef DEBUG
        REP(i, X.size())
        {
            cout << X[i].fi << " : " << bitset<64>(X[i].se) << endl;
        }
        REP(i, Y.size())
        {
            cout << Y[i].fi << " : " << bitset<64>(Y[i].se) << endl;
        }
    #endif

    vi ans;
    REP(i, X.size())
    {
        int t = S - X[i].fi;
        for(auto itr = lower_bound(ALL(Y), mp(t, (int)0)); itr != upper_bound(ALL(Y), mp(t, INF)); itr++)
        {
            ans.push_back((itr->se << (N/2)) + X[i].se);
            //cout << bitset<64>((itr->se << (N/2)) + X[i].se) << endl;
        }
    }

    #ifdef DEBUG
        cout << ans.size() << endl;
    #endif

    vvi output(ans.size());

    REP(i, ans.size())
    {
        REP(j, N)
        {
            if(ans[i] & (1 << j)) output[i].push_back(j+1);
        }
    }

    sort(ALL(output));
    REP(i, output.size())
    {
        REP(j, output[i].size()) cout << output[i][j] << " ";
        cout << endl;
    }
}
0