結果
| 問題 | 
                            No.4 おもりと天秤
                             | 
                    
| コンテスト | |
| ユーザー | 
                             nak3
                         | 
                    
| 提出日時 | 2017-03-11 17:59:20 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 609 bytes | 
| コンパイル時間 | 1,198 ms | 
| コンパイル使用メモリ | 158,512 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-06-24 12:33:50 | 
| 合計ジャッジ時間 | 1,917 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 15 WA * 8 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;
int main()
{
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll sum = accumulate(a, a+n, 0);
	if (sum%2!=0) {
		cout << "impossible" << "\n";
		return 0;
	}
	ll h = sum/2;
	for (int all = 0; all < (1<<n); all++) {
		ll subsum = 0;
		for (int i = 0; i < n; i++) {
			if (all & (1<<i)) {
				subsum += a[i];
			}
		}
		if (subsum==h) {
			cout << "possible" << "\n";
			return 0;
		}
	}
	cout << "impossible" << "\n";
	return 0;
}
            
            
            
        
            
nak3