結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  hotpepsi | 
| 提出日時 | 2014-12-28 15:21:06 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 686 bytes | 
| コンパイル時間 | 558 ms | 
| コンパイル使用メモリ | 64,952 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-26 09:04:35 | 
| 合計ジャッジ時間 | 1,386 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>
#include <numeric>
using namespace std;
typedef vector<int> IntVec;
bool solve(const IntVec &v)
{
	int total = accumulate(v.begin(), v.end(), 0);
	if (total % 2) {
		return false;
	}
	int f[12000] = {};
	f[0] = 1;
	for (int w : v) {
		for (int i = 10000; i >= w; --i) {
			if (f[i - w]) {
				f[i] = 1;
			}
		}
	}
	return f[total / 2] > 0;
}
int main(int argc, char *argv[])
{
	string s;
	getline(cin, s);
	int N = atoi(s.c_str());
	getline(cin, s);
	stringstream ss(s);
	IntVec v(N);
	for (int i = 0; i < N; ++i) {
		ss >> v[i];
	}
	cout << (solve(v) ? "possible" : "impossible") << endl;
	return 0;
}
            
            
            
        