結果

問題 No.247 線形計画問題もどき
ユーザー outlineoutline
提出日時 2021-01-23 18:57:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,549 bytes
コンパイル時間 1,446 ms
コンパイル使用メモリ 139,052 KB
実行使用メモリ 42,904 KB
最終ジャッジ日時 2023-08-30 03:29:48
合計ジャッジ時間 3,456 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
17,320 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 54 ms
42,904 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 4 ms
5,416 KB
testcase_08 AC 3 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 18 ms
12,272 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 44 ms
29,956 KB
testcase_20 AC 53 ms
35,756 KB
testcase_21 AC 12 ms
6,464 KB
testcase_22 AC 17 ms
10,360 KB
testcase_23 AC 12 ms
7,308 KB
testcase_24 AC 53 ms
36,496 KB
testcase_25 AC 41 ms
27,316 KB
testcase_26 AC 9 ms
8,012 KB
testcase_27 AC 13 ms
10,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

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

    vector<vector<int>> dp(N + 1, vector<int>(C + 1, INF));
    dp[0][0] = 0;
    int counter = 0;
    for(int i = 0; i < N; ++i){
        for(int m = 0; m < a[i]; ++m){
            int minv = INF;
            for(int s = m; s <= C; s += a[i]){
                minv += 1;
                chmin(minv, dp[i][s]);
                chmin(dp[i + 1][s], minv);
            }
        }
    }

    int ans = dp[N][C];
    if(ans == INF)  ans = -1;
    cout << ans << endl;

    return 0;
}
0