結果

問題 No.733 分身並列コーディング
ユーザー kimiyukikimiyuki
提出日時 2018-09-07 22:28:47
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 292 ms / 1,500 ms
コード長 954 bytes
コンパイル時間 2,053 ms
コンパイル使用メモリ 202,980 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-19 20:11:26
合計ジャッジ時間 8,973 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 148 ms
4,384 KB
testcase_04 AC 148 ms
4,384 KB
testcase_05 AC 237 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 242 ms
4,380 KB
testcase_08 AC 240 ms
4,380 KB
testcase_09 AC 61 ms
4,384 KB
testcase_10 AC 5 ms
4,384 KB
testcase_11 AC 4 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 21 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 5 ms
4,380 KB
testcase_19 AC 61 ms
4,380 KB
testcase_20 AC 71 ms
4,380 KB
testcase_21 AC 23 ms
4,380 KB
testcase_22 AC 187 ms
4,388 KB
testcase_23 AC 25 ms
4,380 KB
testcase_24 AC 29 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 265 ms
4,384 KB
testcase_29 AC 242 ms
4,380 KB
testcase_30 AC 239 ms
4,380 KB
testcase_31 AC 253 ms
4,384 KB
testcase_32 AC 14 ms
4,380 KB
testcase_33 AC 12 ms
4,380 KB
testcase_34 AC 13 ms
4,384 KB
testcase_35 AC 13 ms
4,384 KB
testcase_36 AC 13 ms
4,384 KB
testcase_37 AC 12 ms
4,380 KB
testcase_38 AC 259 ms
4,380 KB
testcase_39 AC 270 ms
4,384 KB
testcase_40 AC 267 ms
4,384 KB
testcase_41 AC 13 ms
4,380 KB
testcase_42 AC 12 ms
4,380 KB
testcase_43 AC 12 ms
4,384 KB
testcase_44 AC 268 ms
4,384 KB
testcase_45 AC 272 ms
4,384 KB
testcase_46 AC 274 ms
4,380 KB
testcase_47 AC 292 ms
4,380 KB
testcase_48 AC 280 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
using namespace std;
template <class T> inline void chmin(T & a, T const & b) { a = min(a, b); }

int solve(int total, int n, vector<int> const & t) {
    vector<bool> pred(1 << n);
    REP (s, 1 << n) {
        int sum_t = 0;
        REP (i, n) if (s & (1 << i)) {
            sum_t += t[i];
        }
        pred[s] = sum_t <= total;
    }

    vector<int> dp(1 << n, INT_MAX);
    dp[0] = 0;
    REP3 (cur, 1, 1 << n) {
        for (int prv = 0; ; prv = (prv - cur) & cur) {
            if (not pred[cur ^ prv]) continue;
            chmin(dp[cur], dp[prv] + 1);
            if (prv == cur) break;
        }
    }

    return dp[(1 << n) - 1];
}

int main() {
    int total, n; cin >> total >> n;
    vector<int> t(n);
    REP (i, n) cin >> t[i];
    cout << solve(total, n, t) << endl;
    return 0;
}
0