結果

問題 No.1606 Stuffed Animals Keeper
ユーザー pengin_2000pengin_2000
提出日時 2021-07-16 23:08:52
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 67 ms / 3,000 ms
コード長 1,046 bytes
コンパイル時間 729 ms
コンパイル使用メモリ 29,176 KB
実行使用メモリ 99,732 KB
最終ジャッジ日時 2023-09-20 15:34:53
合計ジャッジ時間 4,178 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
99,560 KB
testcase_01 AC 27 ms
99,616 KB
testcase_02 AC 25 ms
99,572 KB
testcase_03 AC 37 ms
99,720 KB
testcase_04 AC 39 ms
99,628 KB
testcase_05 AC 31 ms
99,700 KB
testcase_06 AC 33 ms
99,720 KB
testcase_07 AC 37 ms
99,712 KB
testcase_08 AC 36 ms
99,644 KB
testcase_09 AC 32 ms
99,628 KB
testcase_10 AC 31 ms
99,620 KB
testcase_11 AC 29 ms
99,564 KB
testcase_12 AC 33 ms
99,524 KB
testcase_13 AC 26 ms
99,664 KB
testcase_14 AC 27 ms
99,520 KB
testcase_15 AC 67 ms
99,652 KB
testcase_16 AC 41 ms
99,620 KB
testcase_17 AC 40 ms
99,656 KB
testcase_18 AC 40 ms
99,580 KB
testcase_19 AC 41 ms
99,528 KB
testcase_20 AC 42 ms
99,588 KB
testcase_21 AC 27 ms
99,576 KB
testcase_22 AC 27 ms
99,612 KB
testcase_23 AC 27 ms
99,508 KB
testcase_24 AC 28 ms
99,524 KB
testcase_25 AC 29 ms
99,716 KB
testcase_26 AC 28 ms
99,620 KB
testcase_27 AC 27 ms
99,680 KB
testcase_28 AC 27 ms
99,716 KB
testcase_29 AC 27 ms
99,588 KB
testcase_30 AC 26 ms
99,520 KB
testcase_31 AC 27 ms
99,608 KB
testcase_32 AC 27 ms
99,712 KB
testcase_33 AC 27 ms
99,592 KB
testcase_34 AC 26 ms
99,660 KB
testcase_35 AC 27 ms
99,660 KB
testcase_36 AC 27 ms
99,516 KB
testcase_37 AC 26 ms
99,572 KB
testcase_38 AC 27 ms
99,636 KB
testcase_39 AC 26 ms
99,612 KB
testcase_40 AC 26 ms
99,568 KB
testcase_41 AC 26 ms
99,660 KB
testcase_42 AC 26 ms
99,632 KB
testcase_43 AC 40 ms
99,724 KB
testcase_44 AC 40 ms
99,660 KB
testcase_45 AC 41 ms
99,676 KB
testcase_46 AC 40 ms
99,732 KB
testcase_47 AC 41 ms
99,728 KB
testcase_48 AC 26 ms
99,660 KB
testcase_49 AC 25 ms
99,608 KB
testcase_50 AC 25 ms
99,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i, j;
	int a[5003];
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	a[n] = 2;
	int count[3] = { 0,0,0 };
	for (i = 0; i < n; i++)
		count[a[i]]++;
	int cnt[5003][2], m = 0;
	cnt[0][0] = cnt[0][1] = 0;
	for (i = 0; i <= n; i++)
	{
		if (a[i] == 2)
		{
			m++;
			cnt[m][0] = cnt[m][1] = 0;
		}
		else
			cnt[m][a[i]]++;
	}
	int dp[5003][5003];
	for (i = 0; i < 5003; i++)
		for (j = 0; j < 5003; j++)
			dp[i][j] = -1;
	dp[0][0] = cnt[0][0];
	dp[0][cnt[0][0] + cnt[0][1]] = cnt[0][1];
	for (i = 1; i < m; i++)
	{
		for (j = 0; j < 5003; j++)
		{
			if (dp[i - 1][j] >= 0)
				dp[i][j] = dp[i - 1][j] + cnt[i][0];
			if (j >= cnt[i][0] + cnt[i][1])
			{
				if (dp[i - 1][j - cnt[i][0] - cnt[i][1]] >= 0)
				{
					if (dp[i][j]<0 || dp[i][j]>dp[i - 1][j - cnt[i][0] - cnt[i][1]] + cnt[i][1])
						dp[i][j] = dp[i - 1][j - cnt[i][0] - cnt[i][1]] + cnt[i][1];
				}
			}
		}
	}
	if (dp[m - 1][count[0]] > 0)
		dp[m - 1][count[0]] /= 2;
	printf("%d\n", dp[m - 1][count[0]]);
	return 0;
}
0