結果

問題 No.1606 Stuffed Animals Keeper
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-10 20:17:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,096 bytes
コンパイル時間 1,070 ms
コンパイル使用メモリ 111,876 KB
実行使用メモリ 14,200 KB
最終ジャッジ日時 2023-08-31 00:36:52
合計ジャッジ時間 4,069 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 7 ms
7,596 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 6 ms
7,076 KB
testcase_08 WA -
testcase_09 AC 4 ms
4,848 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 10 ms
10,448 KB
testcase_17 AC 10 ms
10,304 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 11 ms
10,436 KB
testcase_21 AC 4 ms
4,572 KB
testcase_22 AC 4 ms
4,692 KB
testcase_23 AC 4 ms
4,888 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 2 ms
4,376 KB
testcase_33 WA -
testcase_34 AC 3 ms
4,380 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 3 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 WA -
testcase_44 AC 14 ms
13,920 KB
testcase_45 AC 14 ms
13,916 KB
testcase_46 AC 14 ms
13,860 KB
testcase_47 AC 15 ms
14,136 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
using ll = long long;

int main(){

    int N, A, K, x=0, y=0, S=0;
    cin >> N;
    vector<int> L, M;

    for (int i=0; i<N; i++){
        cin >> A;
        if (A == 0) x++;
        else if (A == 1) x++, y++;
        else{
            if (x == 0) continue;
            L.push_back(x); M.push_back(y);
            x = 0; y = 0;
        }
    }
    if (x > 0) L.push_back(x), M.push_back(y);
    K = L.size();
    for (int i=0; i<K; i++) S += L[i]-M[i];
    if (K == 0){
        cout << "Yes" << endl;
        return 0;
    }

    vector<vector<int>> dp(K+1, vector<int>(S+1, 1e9));
    dp[0][0] = 0;
    
    for (int i=1; i<=K; i++){
        for (int j=0; j<=S; j++){
            if (j-L[i-1]>=0) dp[i][j] = min(dp[i-1][j], dp[i-1][j-L[i-1]]+M[i-1]);
        }
    }

    if (dp[K][S] == 1e9) dp[K][S] = -1;
    cout << dp[K][S] << endl;

    return 0;
}
0