結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-06-29 17:48:18 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 636 bytes | 
| コンパイル時間 | 452 ms | 
| コンパイル使用メモリ | 62,916 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-26 10:20:43 | 
| 合計ジャッジ時間 | 1,179 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
#define REP(i, N) for(int i=0;i<(N);++i)
int main() {
    int n; cin >> n;
    vector<int> ws(n); REP(i, n) cin >> ws[i];
    int sum = accumulate(ws.begin(), ws.end(), 0);
    if (sum % 2 == 1) {
        cout << "impossible" << endl;
        return 0;
    }
    int half = sum / 2;
    vector<bool> memo(10000, false);
    memo[0] = true;
    for (int w : ws) {
        for (int i = half; i >= 0; --i) if(memo[i]) memo[i+w] = true;
    }
    if (memo[half]) {
        cout << "possible" << endl;
    } else {
        cout << "impossible" << endl;
    }
}
            
            
            
        