結果

問題 No.733 分身並列コーディング
ユーザー beetbeet
提出日時 2018-09-07 21:26:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,059 ms / 1,500 ms
コード長 766 bytes
コンパイル時間 1,472 ms
コンパイル使用メモリ 167,608 KB
実行使用メモリ 5,384 KB
最終ジャッジ日時 2023-08-19 12:29:48
合計ジャッジ時間 22,724 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 991 ms
5,124 KB
testcase_04 AC 921 ms
5,168 KB
testcase_05 AC 11 ms
5,272 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 860 ms
5,384 KB
testcase_08 AC 783 ms
5,212 KB
testcase_09 AC 313 ms
4,380 KB
testcase_10 AC 14 ms
4,376 KB
testcase_11 AC 15 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 105 ms
4,376 KB
testcase_15 AC 6 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 13 ms
4,380 KB
testcase_19 AC 317 ms
4,376 KB
testcase_20 AC 307 ms
4,376 KB
testcase_21 AC 106 ms
4,376 KB
testcase_22 AC 938 ms
5,244 KB
testcase_23 AC 105 ms
4,376 KB
testcase_24 AC 102 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 6 ms
4,380 KB
testcase_28 AC 874 ms
5,208 KB
testcase_29 AC 1,059 ms
5,272 KB
testcase_30 AC 933 ms
5,168 KB
testcase_31 AC 986 ms
5,160 KB
testcase_32 AC 38 ms
4,376 KB
testcase_33 AC 37 ms
4,376 KB
testcase_34 AC 36 ms
4,376 KB
testcase_35 AC 36 ms
4,380 KB
testcase_36 AC 37 ms
4,376 KB
testcase_37 AC 36 ms
4,380 KB
testcase_38 AC 938 ms
5,244 KB
testcase_39 AC 946 ms
5,236 KB
testcase_40 AC 954 ms
5,140 KB
testcase_41 AC 36 ms
4,376 KB
testcase_42 AC 35 ms
4,380 KB
testcase_43 AC 37 ms
4,376 KB
testcase_44 AC 965 ms
5,120 KB
testcase_45 AC 977 ms
5,136 KB
testcase_46 AC 955 ms
5,072 KB
testcase_47 AC 965 ms
5,240 KB
testcase_48 AC 933 ms
5,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int t,n;
  cin>>t>>n;
  vector<Int> x(n);
  for(Int i=0;i<n;i++) cin>>x[i];

  Int s=1<<n;
  vector<Int> dp(s,-1),sum(s,0);
  for(Int b=0;b<s;b++)
    for(Int i=0;i<n;i++)
      if((b>>i)&1) sum[b]+=x[i];
  
  function<Int(Int)> dfs=
    [&](Int b){
      Int &res=dp[b];
      if(~res) return res;
      if(sum[b]<=t) return res=1;
      res=n+1;
      for(Int i=b;i;i=(i-1)&b){
	if(i==b) continue;
	chmin(res,dfs(i)+dfs(b^i));
      }
      return res;
    };
  
  cout<<dfs(s-1)<<endl;
  return 0;
}
0