結果

問題 No.1606 Stuffed Animals Keeper
ユーザー momoyuumomoyuu
提出日時 2023-11-18 04:35:13
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,665 bytes
コンパイル時間 1,252 ms
コンパイル使用メモリ 112,708 KB
実行使用メモリ 814,336 KB
最終ジャッジ日時 2023-11-18 04:35:17
合計ジャッジ時間 4,616 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 MLE -
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 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<cassert>
#include<set>
using namespace std;
using ll = long long;

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

    int n;
    cin>>n;
    vector<int> a(n);
    for(int i = 0;i<n;i++) cin>>a[i];
    vector<vector<vector<int>>> dp(n+1,vector<vector<int>>(n+1,vector<int>(3,1e9)));
    dp[0][0][2] = 0;

    for(int i = 0;i<n;i++){
        if(a[i]==2){
            for(int j = 0;j<=n;j++){
                dp[i+1][j][2] = min(dp[i+1][j][2],dp[i][j][0]);
                dp[i+1][j][2] = min(dp[i+1][j][2],dp[i][j][1]);
                dp[i+1][j][2] = min(dp[i+1][j][2],dp[i][j][2]);
            }
            continue;
        }
        for(int j = 0;j<=n;j++){
            if(a[i]==0){
                if(j+1<=n) dp[i+1][j+1][0] = min(dp[i+1][j+1][0],dp[i][j][0]);
                if(j+1<=n) dp[i+1][j+1][0] = min(dp[i+1][j+1][0],dp[i][j][2]);
                dp[i+1][j][1] = min(dp[i+1][j][1],dp[i][j][1]+1);
                dp[i+1][j][1] = min(dp[i+1][j][1],dp[i][j][2]+1);
            }else{
                if(j+1<=n) dp[i+1][j+1][0] = min(dp[i+1][j+1][0],dp[i][j][0]+1);
                if(j+1<=n) dp[i+1][j+1][0] = min(dp[i+1][j+1][0],dp[i][j][2]+1);
                dp[i+1][j][1] = min(dp[i+1][j][1],dp[i][j][1]);
                dp[i+1][j][1] = min(dp[i+1][j][1],dp[i][j][2]);
            }
        }
    }
    int ans = 1e9;
    int cnt = 0;
    for(int i = 0;i<n;i++) if(a[i]==0) cnt++;
    ans = dp[n][cnt][0];
    ans = min(ans,dp[n][cnt][1]);
    ans = min(ans,dp[n][cnt][2]);
    if(ans==1e9) ans = -1;
    else ans = ans / 2;
    cout<<ans<<endl;
}

0