結果

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

ソースコード

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);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 20000; j++){
			if(dp[j] == 1)dp[j + a[i]] = 1;
		}
		dp[a[i]] = 1;
	}
	if(dp[sum / 2] == 1){
		cout << "possible" << endl;
	}else{
		cout << "impossible" << endl;
	}
	return 0;
}
0