結果
| 問題 | No.15 カタログショッピング | 
| コンテスト | |
| ユーザー |  y_mazun | 
| 提出日時 | 2015-04-24 01:02:45 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 32 ms / 5,000 ms | 
| コード長 | 957 bytes | 
| コンパイル時間 | 845 ms | 
| コンパイル使用メモリ | 72,696 KB | 
| 実行使用メモリ | 6,784 KB | 
| 最終ジャッジ日時 | 2024-07-05 00:44:17 | 
| 合計ジャッジ時間 | 1,542 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 10 | 
コンパイルメッセージ
main.cpp: In function ‘int getInt()’:
main.cpp:5:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    5 | inline int getInt(){ int s; scanf("%d", &s); return s; }
      |                             ~~~~~^~~~~~~~~~
            
            ソースコード
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }
#include <map>
#include <queue>
#include <set>
using namespace std;
int main(){
  const int n = getInt();
  const int s = getInt();
  vector<int> p(n);
  REP(i,n) p[i] = getInt();
  map<int, vector<int> > m;
  REP(i,1<<(n/2)){
    int s = 0;
    REP(j,n/2) if(i & (1 << j)) s += p[j];
    m[s].push_back(i);
  }
  vector<vector<int> > ans;
  REP(i,1<<(n/2+n%2)){
    int t = 0;
    REP(j,n/2+n%2) if(i & (1 << j)) t += p[n/2 + j];
    if(m.count(s - t)){
      REP(j,m[s-t].size()){
        vector<int> tmp;
        const int f = m[s-t][j] | (i << (n/2));
        REP(k,n) if(f & (1 << k))
          tmp.push_back(k + 1);
        ans.push_back(tmp);
      }
    }
  }
  sort(ans.begin(), ans.end());
  REP(i,ans.size()){
    REP(j,ans[i].size()) printf("%d ", ans[i][j]);
    puts("");
  }
  return 0;
}
            
            
            
        