結果

問題 No.1606 Stuffed Animals Keeper
ユーザー outlineoutline
提出日時 2021-08-01 18:10:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,293 bytes
コンパイル時間 1,638 ms
コンパイル使用メモリ 135,120 KB
実行使用メモリ 296,788 KB
最終ジャッジ日時 2023-10-14 18:58:43
合計ジャッジ時間 11,907 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 160 ms
205,296 KB
testcase_04 AC 193 ms
246,468 KB
testcase_05 AC 36 ms
82,364 KB
testcase_06 AC 62 ms
111,608 KB
testcase_07 AC 140 ms
185,312 KB
testcase_08 AC 113 ms
172,320 KB
testcase_09 AC 50 ms
99,116 KB
testcase_10 AC 30 ms
77,120 KB
testcase_11 AC 18 ms
63,868 KB
testcase_12 AC 59 ms
109,740 KB
testcase_13 AC 245 ms
296,512 KB
testcase_14 AC 184 ms
296,456 KB
testcase_15 AC 186 ms
296,472 KB
testcase_16 WA -
testcase_17 AC 185 ms
296,464 KB
testcase_18 AC 185 ms
296,740 KB
testcase_19 AC 183 ms
296,520 KB
testcase_20 AC 185 ms
296,532 KB
testcase_21 AC 181 ms
296,532 KB
testcase_22 AC 179 ms
296,472 KB
testcase_23 AC 179 ms
296,488 KB
testcase_24 AC 178 ms
296,460 KB
testcase_25 AC 179 ms
296,472 KB
testcase_26 AC 182 ms
296,456 KB
testcase_27 AC 181 ms
296,468 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 187 ms
296,456 KB
testcase_33 WA -
testcase_34 AC 190 ms
296,452 KB
testcase_35 AC 185 ms
296,472 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 205 ms
296,452 KB
testcase_39 AC 188 ms
296,516 KB
testcase_40 AC 188 ms
296,600 KB
testcase_41 AC 185 ms
296,520 KB
testcase_42 WA -
testcase_43 AC 185 ms
296,480 KB
testcase_44 AC 186 ms
296,484 KB
testcase_45 AC 185 ms
296,744 KB
testcase_46 AC 184 ms
296,544 KB
testcase_47 AC 184 ms
296,476 KB
testcase_48 AC 1 ms
4,348 KB
testcase_49 AC 2 ms
4,352 KB
testcase_50 AC 2 ms
4,352 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;

// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")

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 dp[5001][5001][3];

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

    int N, zero = 0;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; ++i){
        cin >> A[i];
        zero += A[i] == 0;
    }

    for(int i = 0; i <= N; ++i){
        for(int j = 0; j <= N; ++j){
            for(int k = 0; k <= 2; ++k){
                dp[i][j][k] = INF;
            }
        }
    }

    dp[0][0][2] = 0;
    for(int i = 0; i < N; ++i){
        if(A[i] == 2){
            for(int j = 0; j <= i; ++j){
                for(int k = 0; k <= 2; ++k){
                    chmin(dp[i + 1][j][2], dp[i][j][k]);
                }
            }
        }
        else{
            for(int j = 0; j <= i; ++j){
                chmin(dp[i + 1][j + 1][0], dp[i][j][0] + (A[i] == 1));
                chmin(dp[i + 1][j][1], dp[i][j][1] + (A[i] == 0));
                chmin(dp[i + 1][j + 1][0], dp[i][j][2] + (A[i] == 1));
                chmin(dp[i + 1][j][1], dp[i][j][2] + (A[i] == 0));
            }
        }
    }

    int ans = dp[N][zero][A[N - 1]];
    if(ans == INF)  ans = -1;
    else    ans /= 2;

    cout << ans << endl;

    return 0;
}
0