結果

問題 No.733 分身並列コーディング
ユーザー T1610T1610
提出日時 2020-07-29 16:12:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 253 ms / 1,500 ms
コード長 1,028 bytes
コンパイル時間 1,936 ms
コンパイル使用メモリ 199,728 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-11 11:06:20
合計ジャッジ時間 9,662 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 252 ms
4,376 KB
testcase_04 AC 253 ms
4,376 KB
testcase_05 AC 253 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 252 ms
4,376 KB
testcase_08 AC 253 ms
4,376 KB
testcase_09 AC 87 ms
4,376 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 31 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 86 ms
4,380 KB
testcase_20 AC 87 ms
4,376 KB
testcase_21 AC 30 ms
4,376 KB
testcase_22 AC 253 ms
4,380 KB
testcase_23 AC 31 ms
4,376 KB
testcase_24 AC 31 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 253 ms
4,376 KB
testcase_29 AC 253 ms
4,376 KB
testcase_30 AC 252 ms
4,376 KB
testcase_31 AC 253 ms
4,376 KB
testcase_32 AC 11 ms
4,376 KB
testcase_33 AC 12 ms
4,380 KB
testcase_34 AC 12 ms
4,380 KB
testcase_35 AC 12 ms
4,376 KB
testcase_36 AC 12 ms
4,376 KB
testcase_37 AC 12 ms
4,380 KB
testcase_38 AC 253 ms
4,380 KB
testcase_39 AC 252 ms
4,376 KB
testcase_40 AC 253 ms
4,376 KB
testcase_41 AC 12 ms
4,380 KB
testcase_42 AC 11 ms
4,376 KB
testcase_43 AC 12 ms
4,376 KB
testcase_44 AC 253 ms
4,376 KB
testcase_45 AC 253 ms
4,376 KB
testcase_46 AC 252 ms
4,380 KB
testcase_47 AC 252 ms
4,376 KB
testcase_48 AC 253 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int t, n;
    cin >> t >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    vi dp(1<<n, 1e9);
    dp[0] = 0;
    REP(mask, 1, 1<<n) {
        int sum = 0;
        rep(i, n) if(mask&(1<<i)) sum += a[i];
        if(sum <= t) dp[mask] = 1;
    }
    REP(mask, 1, 1<<n) {
        for(int A = mask-1; A > 0; A=(A-1)&mask) {
            int B = mask - A;
            chmin(dp[mask], dp[A]+dp[B]);
        }
    }
    cout << dp[(1<<n)-1] << '\n';
    return 0;
}
0