結果

問題 No.247 線形計画問題もどき
ユーザー JohnNakazawaJohnNakazawa
提出日時 2015-07-17 23:13:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,845 bytes
コンパイル時間 1,432 ms
コンパイル使用メモリ 147,988 KB
実行使用メモリ 42,808 KB
最終ジャッジ日時 2023-09-21 17:23:17
合計ジャッジ時間 2,920 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
17,416 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 64 ms
42,808 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 4 ms
5,336 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 14 ms
12,276 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 38 ms
30,112 KB
testcase_20 AC 47 ms
35,872 KB
testcase_21 AC 5 ms
6,368 KB
testcase_22 AC 11 ms
10,456 KB
testcase_23 AC 6 ms
7,460 KB
testcase_24 AC 47 ms
36,652 KB
testcase_25 AC 35 ms
27,224 KB
testcase_26 AC 7 ms
7,992 KB
testcase_27 AC 10 ms
10,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define rep(i, N) for (int i = 0; i < (int)(N); i++)
#define REP(i, init, N) for (int i = (init); i < (int)(N); i++)

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const double EPS = 1e-12;
//const double PI = acos(-1.0);

int main(void) {
    int C, N;
    cin >> C >> N;
    VI as(N);
    for (auto &a : as) cin >> a;

    VVI dp(N + 1, VI(C + 1, INF));
    dp[0][0] = 0;
    rep(i, N) {
        rep(j, C + 1) {
            if (dp[i][j] == INF) continue;
            int c = j;
            int v = dp[i][j];
            
            dp[i + 1][c] = min(dp[i + 1][c], v);

            c += as[i];
            v += 1;
            if (c > C) continue;
            dp[i][c] = min(dp[i][c], v);
        }
    }

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

	return 0;
}
0