結果

問題 No.247 線形計画問題もどき
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2022-12-31 05:54:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 752 bytes
コンパイル時間 1,080 ms
コンパイル使用メモリ 112,056 KB
実行使用メモリ 82,992 KB
最終ジャッジ日時 2023-08-17 09:02:58
合計ジャッジ時間 2,555 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
31,556 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 82 ms
82,992 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 5 ms
8,028 KB
testcase_08 AC 3 ms
5,484 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 3 ms
5,412 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,500 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 19 ms
21,748 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 51 ms
57,112 KB
testcase_20 AC 65 ms
68,376 KB
testcase_21 AC 8 ms
9,912 KB
testcase_22 AC 16 ms
18,068 KB
testcase_23 AC 10 ms
11,496 KB
testcase_24 AC 66 ms
69,752 KB
testcase_25 AC 48 ms
51,356 KB
testcase_26 AC 10 ms
13,176 KB
testcase_27 AC 16 ms
18,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;

int main(){

    long long C, N;
    cin >> C >> N;
    vector<long long> a(N+1);
    for (int i=1; i<=N; i++) cin >> a[i];
    vector<vector<long long>> dp(N+1, vector<long long>(C+1, 1e18));
    for (int i=0; i<=N; i++) dp[i][0] = 0;

    for (int i=1; i<=N; i++){
        for (int j=1; j<=C; j++){
            dp[i][j] = min(dp[i][j], dp[i-1][j]);
            if (j >= a[i]) dp[i][j] = min(dp[i][j], dp[i][j-a[i]] + 1);
        }
    }

    cout << (dp[N][C] == 1e18 ? -1 : dp[N][C]) << endl;

    return 0;
}
0