結果

問題 No.247 線形計画問題もどき
ユーザー 👑 jupirojupiro
提出日時 2020-07-14 01:09:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,801 bytes
コンパイル時間 1,336 ms
コンパイル使用メモリ 130,452 KB
実行使用メモリ 11,036 KB
最終ジャッジ日時 2024-04-26 16:40:09
合計ジャッジ時間 5,146 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;



int dp[2][100001];

void init(int x) {
    for (int i = 0; i <= 100000; i++) dp[x][i] = inf;
}
int main()
{
    /*
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    */

    int C; scanf("%d", &C);
    int n; scanf("%d", &n);
    vector<int> a(n); for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    init(0), init(1);
    int cur = 0;
    int nxt = 1;
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        init(nxt);
        for (int j = 0; j <= C; j++) {
            if (dp[cur][j] == -inf) continue;
            for (int k = 0; k <= C; k++) {
                if (a[i] * k + j > C) break;
                chmin(dp[nxt][a[i] * k + j], dp[cur][j] + k);
            }
        }
        swap(cur, nxt);
    }
    int res = dp[cur][C];
    if (res == inf) res = -1;
    cout << res << endl;
    return 0;
}
0