結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2015-01-18 06:34:31 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                WA
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 689 bytes | 
| コンパイル時間 | 756 ms | 
| コンパイル使用メモリ | 66,352 KB | 
| 実行使用メモリ | 10,272 KB | 
| 最終ジャッジ日時 | 2024-06-22 19:03:47 | 
| 合計ジャッジ時間 | 7,925 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 17 WA * 1 TLE * 1 -- * 4 | 
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
int n;
vector<int> w;
int half;
bool add(int sum, int idx) {
	if (sum == half) {
		return true;
	} else if (sum > half) {
		return false;
	}
	for (int i = idx + 1; i < n; i++) {
		if(add(sum + w[idx], i)) {
			return true;
		}
	}
	return false;
}
int main() {
	cin >> n;
	int total = 0;
	w.assign(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		total += w[i];
	}
	sort(w.begin(), w.end(), greater<int>());
	bool ret = false;
	if (total % 2 == 0) {
		half = total / 2;
		ret = add(0, 0);
	}
	cout << (ret ? "possible" : "impossible") << endl;
	return 0;
}
            
            
            
        