結果

問題 No.1606 Stuffed Animals Keeper
ユーザー rtyurtyu
提出日時 2021-07-16 21:55:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 3,000 ms
コード長 829 bytes
コンパイル時間 1,444 ms
コンパイル使用メモリ 72,900 KB
実行使用メモリ 35,392 KB
最終ジャッジ日時 2023-09-20 13:47:01
合計ジャッジ時間 2,695 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 9 ms
20,752 KB
testcase_04 AC 9 ms
22,784 KB
testcase_05 AC 4 ms
10,200 KB
testcase_06 AC 6 ms
14,404 KB
testcase_07 AC 7 ms
18,736 KB
testcase_08 AC 8 ms
18,584 KB
testcase_09 AC 5 ms
12,380 KB
testcase_10 AC 4 ms
10,092 KB
testcase_11 AC 3 ms
8,000 KB
testcase_12 AC 5 ms
14,596 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 11 ms
24,904 KB
testcase_17 AC 11 ms
24,900 KB
testcase_18 AC 12 ms
24,928 KB
testcase_19 AC 11 ms
25,008 KB
testcase_20 AC 11 ms
24,928 KB
testcase_21 AC 4 ms
6,868 KB
testcase_22 AC 4 ms
6,872 KB
testcase_23 AC 5 ms
7,072 KB
testcase_24 AC 4 ms
6,764 KB
testcase_25 AC 4 ms
6,768 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 3 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 15 ms
35,260 KB
testcase_44 AC 15 ms
35,308 KB
testcase_45 AC 15 ms
35,192 KB
testcase_46 AC 15 ms
35,216 KB
testcase_47 AC 16 ms
35,392 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

vector<pair<int, int> > v;
int d[5009][5009], inf = 1000000000;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	int m = 0, c0 = 0, c1 = 0;
	for (int i = 0; i <= n; i++) {
		int a = 2;
		if (i < n) cin >> a;
		if (a == 0) {
			c0++; m++;
		}
		else if (a == 1) c1++;
		else if (c0 || c1) {
			v.push_back(make_pair(c0 + c1, c1));
			c0 = c1 = 0;
		}
	}
	for (int i = 1; i <= m; i++)
		d[0][i] = inf;
	for (int i = 1; i <= v.size(); i++) {
		int a = v[i - 1].first, w = v[i - 1].second;
		for (int j = 0; j <= m; j++) {
			d[i][j] = d[i - 1][j];
			if (j >= a) d[i][j] = min(d[i][j], d[i - 1][j - a] + w);
		}
	}
	int ans = d[(int)v.size()][m];
	if (ans >= inf) cout << -1 << '\n';
	else cout << ans << '\n';
	return 0;
}
0