結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  めうめう🎒 | 
| 提出日時 | 2016-03-13 23:02:30 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 1,000 bytes | 
| コンパイル時間 | 863 ms | 
| コンパイル使用メモリ | 74,996 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-26 09:27:11 | 
| 合計ジャッジ時間 | 1,454 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)
int n,w[101],make_num,max_make[101];
bool used[101][10010] = {};
bool bfs(int now,int sum){
	if(sum == make_num) {
		return true;
	}
	if(sum > make_num || now == -1 || sum + max_make[now] < make_num) return false;
	if(used[now][sum]) return false;
	used[now][sum] = true;
	return (bfs(now - 1,sum + w[now]) || bfs(now - 1,sum));
}
int main() {
	bool ans = false;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> w[i];
		make_num += w[i];
		if(i == 0) max_make[i] = w[i];
		else max_make[i] = max_make[i-1] + w[i];
	}
	sort(w,w + n);
	if(make_num % 2 == 1) ans = false;
	else{
		make_num = make_num / 2;
		ans = bfs(n-1,0);
	}
	if(ans) cout << "possible" << endl;
	else cout << "impossible" << endl;
	return 0;
}
            
            
            
        