結果

問題 No.15 カタログショッピング
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-06-11 11:02:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,935 bytes
コンパイル時間 1,730 ms
コンパイル使用メモリ 176,796 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 20:52:27
合計ジャッジ時間 2,349 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main(){cin.tie(0);ios::sync_with_stdio(0);_main();}
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/




int N, S, P[32];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> S;
    rep(i, 0, N) cin >> P[i];

    if (N == 1) {
        printf("1\n");
        return;
    }

    int M = N / 2;
    vector<pair<int, int>> v;
    rep(mask, 0, 1 << M) {
        int sm = 0;
        rep(i, 0, M) if (mask & (1 << i)) sm += P[i];
        v.push_back({ sm, mask });
    }
    sort(v.begin(), v.end());

    int MM = N - M;
    rep(mask, 0, 1 << MM) {
        int sm = 0;
        rep(i, 0, MM) if (mask & (1 << i)) sm += P[M + i];
        auto ite = lower_bound(v.begin(), v.end(), make_pair(S - sm, -1));
        while (ite != v.end()) {
            if (ite->first != S - sm) break;

            vector<int> ans;
            rep(i, 0, M) if (ite->second & (1 << i)) ans.push_back(i + 1);
            rep(i, 0, MM) if (mask & (1 << i)) ans.push_back(M + i + 1);
            rep(i, 0, ans.size()) {
                if (0 < i) printf(" ");
                printf("%d", ans[i]);
            }
            printf("\n");

            ite++;
        }
    }
}
0