結果

問題 No.4 おもりと天秤
ユーザー rodea
提出日時 2017-10-11 15:06:35
言語 C
(gcc 13.3.0)
結果
RE  
実行時間 -
コード長 493 bytes
コンパイル時間 131 ms
コンパイル使用メモリ 29,440 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-17 09:40:00
合計ジャッジ時間 1,946 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 RE * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int n, i, j, ans, a[100], dp[100][5000] = { 0 };

int main(void)
{
	scanf("%d", &n);

	for (i = 0; i<n; i++)
	{
		scanf("%d", &a[i]);
		ans += a[i];
	}

	if (ans % 2 == 1)
	{
		printf("impossible\n");
		return 0;
	}

	dp[0][0] = 1;
	for (i = 0; i < n; ++i) 
	{
		for (j = 0; j <= 5000; ++j) 
		{
			if (dp[i][j] == 1) 
			{
				dp[i + 1][j + a[i]] = 1;
				dp[i + 1][j] = 1;
			}
		}
	}


	if (dp[n][ans/2]) printf("possible\n");
	else printf("impossible\n");

	return 0;
}
0