結果

問題 No.1606 Stuffed Animals Keeper
ユーザー yakkiyakki
提出日時 2021-07-16 22:30:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,741 bytes
コンパイル時間 2,057 ms
コンパイル使用メモリ 122,880 KB
実行使用メモリ 199,732 KB
最終ジャッジ日時 2023-09-20 14:47:53
合計ジャッジ時間 7,125 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
199,648 KB
testcase_01 AC 54 ms
199,348 KB
testcase_02 AC 53 ms
199,636 KB
testcase_03 AC 65 ms
199,448 KB
testcase_04 AC 67 ms
199,544 KB
testcase_05 AC 55 ms
199,368 KB
testcase_06 AC 58 ms
199,520 KB
testcase_07 AC 62 ms
199,504 KB
testcase_08 AC 63 ms
199,500 KB
testcase_09 AC 56 ms
199,488 KB
testcase_10 AC 55 ms
199,424 KB
testcase_11 AC 54 ms
199,440 KB
testcase_12 AC 58 ms
199,456 KB
testcase_13 AC 53 ms
199,656 KB
testcase_14 AC 54 ms
199,512 KB
testcase_15 AC 87 ms
199,460 KB
testcase_16 AC 72 ms
199,440 KB
testcase_17 AC 72 ms
199,436 KB
testcase_18 AC 72 ms
199,444 KB
testcase_19 AC 70 ms
199,692 KB
testcase_20 AC 71 ms
199,460 KB
testcase_21 WA -
testcase_22 AC 55 ms
199,624 KB
testcase_23 WA -
testcase_24 AC 55 ms
199,348 KB
testcase_25 AC 55 ms
199,428 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 54 ms
199,448 KB
testcase_33 WA -
testcase_34 AC 53 ms
199,340 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 54 ms
199,624 KB
testcase_40 WA -
testcase_41 AC 54 ms
199,364 KB
testcase_42 AC 54 ms
199,444 KB
testcase_43 AC 69 ms
199,484 KB
testcase_44 AC 69 ms
199,456 KB
testcase_45 AC 70 ms
199,392 KB
testcase_46 AC 69 ms
199,464 KB
testcase_47 AC 69 ms
199,396 KB
testcase_48 AC 54 ms
199,432 KB
testcase_49 AC 54 ms
199,396 KB
testcase_50 AC 54 ms
199,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<ctime>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0)

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
//using mint = modint998244353;

int dh[] = {1,0,-1,0};
int dw[] = {0,1,0,-1};

ll dp[5010][5010];

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int cnt0 = 0,cnt1 = 0;
    vector<Pi> v;
    rep(i,n){
        if(a[i] == 2){
            v.emplace_back(cnt0,cnt1);
            cnt0 = 0;
            cnt1 = 0;
        }
        else if(a[i] == 0) cnt0++;
        else cnt1++;
    }
    v.emplace_back(cnt0,cnt1);

    int m = v.size();
    rep(i,5010)rep(j,5010) dp[i][j] = LINF;
    dp[0][0] = 0;
    rep(i,m){
        int u = v[i].first;
        int w = v[i].second;
        rep(j,n+1){
            if(dp[i][j] == LINF) continue;
            dp[i+1][j+u] = min(dp[i+1][j+u],dp[i][j]+u);
            dp[i+1][j+w] = min(dp[i+1][j+w],dp[i][j]+w);
            if(j >= w) dp[i+1][j-w] = min(dp[i+1][j-w],dp[i][j]);
            if(j >= u) dp[i+1][j-u] = min(dp[i+1][j-u],dp[i][j]);
        }
    }
    if(dp[m][0] == LINF) cout << -1 << endl;
    else cout << dp[m][0] << endl;

}

0