結果

問題 No.733 分身並列コーディング
ユーザー minatominato
提出日時 2020-02-25 16:12:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 195 ms / 1,500 ms
コード長 1,167 bytes
コンパイル時間 2,059 ms
コンパイル使用メモリ 173,716 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 13:40:11
合計ジャッジ時間 7,514 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const double PI = acos(-1.0);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int T,N; cin >> T >> N;
    vector<int> t(N);
    rep(i,N) cin >> t[i];

    vector<int> dp(1<<N,1e9);
    rep(mask,1<<N) {
        int val = 0;
        rep(i,N) {
            if (mask&(1<<i)) val += t[i]; 
        }
        if (val <= T) dp[mask] = 1; 
    }

    rep(mask,1<<N) {
        for (int i = mask; i > 0; i = (i-1)&mask) {
            chmin(dp[mask],dp[i]+dp[i^mask]);
        }
    }

    cout << dp[(1<<N)-1] << ln;
}
0