結果

問題 No.15 カタログショッピング
ユーザー どららどらら
提出日時 2015-06-02 23:13:43
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,577 bytes
コンパイル時間 2,361 ms
コンパイル使用メモリ 100,528 KB
実行使用メモリ 814,684 KB
最終ジャッジ日時 2023-09-20 18:55:17
合計ジャッジ時間 6,017 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

ll N, S, p;
vector<ll> P;
map<ll,vector<int> > dp[35];

vector< vector<int> > ret;
bool operator<(const vector<int>& a, const vector<int>& b){
  int i = 0;
  while(i<a.size() && i<b.size()){
    if(a[i] < b[i]) return true;
    if(a[i] > b[i]) return false;
  }
  return a.size() < b.size();
}


void dfs(ll val, int idx, vector<int> v){
  if(val == 0){
    sort(ALLOF(v));
    ret.push_back(v);
    return;
  }

  vector<int> w = dp[idx][val];

  rep(i,w.size()){
    if(w[i] == -1){
      dfs(val, idx-1, v);
    }else{
      vector<int> vv = v;
      vv.push_back(w[i]+1);
      dfs(val-P[w[i]], idx-1, vv);
    }
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin >> N >> S;
  rep(i,N){
    cin >> p;
    P.push_back(p);
  }

  dp[0][0].push_back(-1);
  rep(i,N){
    FOR(it,dp[i]){
      dp[i+1][it->first].push_back(-1);
      dp[i+1][it->first + P[i]].push_back(i);
    }
  }

  dfs(S, N, vector<int>());

  sort(ALLOF(ret));
  
  rep(i,ret.size()){
    rep(j,ret[i].size()){
      if(j!=0) cout << " ";
      cout << ret[i][j];
    }
    cout << endl;
  }
  return 0;
}
0