結果

問題 No.733 分身並列コーディング
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-09-07 23:19:04
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 196 ms / 1,500 ms
コード長 607 bytes
コンパイル時間 755 ms
コンパイル使用メモリ 73,456 KB
実行使用メモリ 4,648 KB
最終ジャッジ日時 2023-08-19 23:12:58
合計ジャッジ時間 6,337 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 196 ms
4,380 KB
testcase_04 AC 187 ms
4,380 KB
testcase_05 AC 190 ms
4,512 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 187 ms
4,512 KB
testcase_08 AC 188 ms
4,380 KB
testcase_09 AC 62 ms
4,384 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 22 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 4 ms
4,384 KB
testcase_19 AC 62 ms
4,380 KB
testcase_20 AC 65 ms
4,380 KB
testcase_21 AC 23 ms
4,380 KB
testcase_22 AC 190 ms
4,424 KB
testcase_23 AC 23 ms
4,376 KB
testcase_24 AC 22 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 190 ms
4,492 KB
testcase_29 AC 191 ms
4,516 KB
testcase_30 AC 189 ms
4,376 KB
testcase_31 AC 188 ms
4,384 KB
testcase_32 AC 9 ms
4,380 KB
testcase_33 AC 9 ms
4,376 KB
testcase_34 AC 10 ms
4,380 KB
testcase_35 AC 9 ms
4,380 KB
testcase_36 AC 9 ms
4,376 KB
testcase_37 AC 9 ms
4,376 KB
testcase_38 AC 187 ms
4,424 KB
testcase_39 AC 187 ms
4,648 KB
testcase_40 AC 186 ms
4,384 KB
testcase_41 AC 9 ms
4,376 KB
testcase_42 AC 8 ms
4,376 KB
testcase_43 AC 9 ms
4,376 KB
testcase_44 AC 186 ms
4,376 KB
testcase_45 AC 185 ms
4,568 KB
testcase_46 AC 188 ms
4,572 KB
testcase_47 AC 187 ms
4,380 KB
testcase_48 AC 187 ms
4,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;

typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
const int N=17;
int u[1<<N],dp[1<<N];
const int inf=1e7;
int main(){
    int t,n;cin>>t>>n;
    vi a(n);rep(i,n)cin>>a[i];
    rep(i,1<<n){
        int s=0;
        rep(j,n)if(i&1<<j)s+=a[j];
        u[i]=s<=t?1:inf;
    }
    rep(i,1<<n)dp[i]=i==0?0:inf;
    rep(i,1<<n){
        if(i==0)continue;
        int s=(i-1)&i;
        while(1){
            dp[i]=min(dp[i],dp[s]+u[i-s]);
            if(s==0)break;
            s=(s-1)&i;
        }
    }
    cout<<dp[(1<<n)-1]<<endl;
}
0