結果

問題 No.4 おもりと天秤
ユーザー mmn15277198
提出日時 2021-01-29 12:53:41
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 647 bytes
コンパイル時間 1,725 ms
コンパイル使用メモリ 169,896 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-27 00:29:25
合計ジャッジ時間 2,532 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

const ld pi = 3.14159265358979;
const int mod = 1000000007;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	int sum = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		sum += a[i];
	}
	
	if(sum % 2 == 1){
		cout << "impossible" << endl;
		exit(0);
	}

	vector<int> dp(30000 , 0);
	dp[0] = 1;
	for(int i = 0; i < n; i++){
		vector<int> dp2;
		dp2 = dp;
		for(int j = 0; j < 20000; j++){
			if(dp[j] == 1)dp2[j + a[i]] = 1;
		}
		dp = dp2;
	}
	if(dp[sum / 2] == 1){
		cout << "possible" << endl;
	}else{
		cout << "impossible" << endl;
	}
	return 0;
}
0