結果

問題 No.4 おもりと天秤
ユーザー silopysilopy
提出日時 2019-06-28 23:14:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 544 bytes
コンパイル時間 691 ms
コンパイル使用メモリ 66,756 KB
実行使用メモリ 7,892 KB
最終ジャッジ日時 2023-09-14 22:38:37
合計ジャッジ時間 2,142 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,816 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 4 ms
7,748 KB
testcase_03 AC 4 ms
7,616 KB
testcase_04 AC 4 ms
7,600 KB
testcase_05 AC 4 ms
7,640 KB
testcase_06 AC 2 ms
7,764 KB
testcase_07 AC 4 ms
7,608 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 5 ms
7,636 KB
testcase_10 AC 5 ms
7,712 KB
testcase_11 AC 3 ms
7,892 KB
testcase_12 AC 3 ms
7,780 KB
testcase_13 AC 4 ms
7,696 KB
testcase_14 AC 4 ms
7,704 KB
testcase_15 AC 4 ms
7,632 KB
testcase_16 AC 4 ms
7,844 KB
testcase_17 AC 3 ms
7,604 KB
testcase_18 AC 4 ms
7,624 KB
testcase_19 AC 3 ms
7,696 KB
testcase_20 AC 4 ms
7,696 KB
testcase_21 AC 4 ms
7,688 KB
testcase_22 AC 4 ms
7,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
using lint=int64_t;

int main()
{
	int N;
	int W[110];
	int sum=0;

	cin >> N;
	for(int i=1;i<=N;i++)
	{
		cin >> W[i];
		sum+=W[i];
	}

	if(sum%2==1)
	{
		cout << "impossible" << endl;
		return 0;
	}

	sum/=2;
	int dp[110][10010]={};
	dp[0][0]=true;
	for(int i=1;i<=N;i++)
	{
		for(int j=0;j<=sum;j++)
		{
			dp[i][j]|=dp[i-1][j];
			if(j-W[i]>=0)
				dp[i][j]|=dp[i-1][j-W[i]];
		}
	}

	if(dp[N][sum])
		cout << "possible";
	else
		cout << "impossible";
	cout << endl;
	return 0;
}
0