結果

問題 No.4 おもりと天秤
ユーザー Naoyk1212
提出日時 2017-06-07 14:52:56
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 335 ms / 5,000 ms
コード長 804 bytes
コンパイル時間 870 ms
コンパイル使用メモリ 85,900 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-26 10:19:09
合計ジャッジ時間 2,892 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <functional>
#include <complex>
#include <cmath>
#include <ccomplex>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		sum += v[i];
	}

	if (sum % 2 != 0) {
		cout << "impossible" << endl;
		return 0;
	}
	else {
		sum /= 2;
	}
	
	bool dp[10010];
	for (int i = 0; i < 10010; i++)dp[i] = false;

	dp[0] = true;
	
	for (int i = 0; i < n; i++) {
		for (int j = sum * 2; j >= 0; j--) {
			if (dp[j]) {
				cerr << j + v[i] << endl;
				dp[j + v[i]] = true;
				if (j + v[i] == sum) {
					cout << "possible" << endl;
					return 0;
				}
			}
		}
	}
	cout << "impossible" << endl;
	
}
0