結果

問題 No.247 線形計画問題もどき
ユーザー machymachy
提出日時 2015-07-17 23:24:30
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 916 bytes
コンパイル時間 487 ms
コンパイル使用メモリ 67,252 KB
実行使用メモリ 36,688 KB
最終ジャッジ日時 2023-09-22 18:15:37
合計ジャッジ時間 3,075 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int C, N;
    cin >> C >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    for(int i = 1; i < a.size(); i++){
        if(a[i] == a[i-1]){
            a.erase(a.begin()+i);
            i--;
        }
    }
    N = a.size();
    vector<vector<int> > dp(N+1, vector<int>(C+1, 1000*1000*1000));
    dp[0][0] = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < a[i]; j++){
            if(dp[i][j] == 1000*1000*1000) continue;
            int cost = dp[i][j];
            for(int k = j; k <= C; k += a[i]){
                dp[i+1][k] = min(dp[i][k], min(dp[i+1][k], cost));
                cost = dp[i+1][k] + 1;
            }
        }
    }
    if(dp[N][C] == 1000*1000*1000){
        cout << -1 << endl;
    }else{
        cout << dp[N][C] << endl;
    }
    return 0;
}
0