結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2016-04-18 11:28:14 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 1,008 bytes | 
| コンパイル時間 | 483 ms | 
| コンパイル使用メモリ | 59,864 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-26 09:28:29 | 
| 合計ジャッジ時間 | 1,315 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#include <iostream>
#include <vector>
using namespace std;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n;
    cin >> n;
    vector<int> vec(n);
    int sum = 0;
    for (auto& i : vec) {
        cin >> i;
        sum += i;
    }
    vector<int> x(sum + 1, 0);
    x.at(0) = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = sum; j >= vec.at(i); --j) {
            x.at(j) |= x.at(j - vec.at(i));
        }
    }
    cout <<((x.at(sum / 2) && sum % 2 == 0) ? "possible" : "impossible") << endl;
    return 0;
}
// 3 2 1 , sum=6 
// 5 4 3 2 , sum=14
// 2 3 5 9 10 11 12 sum=52
// 88 15 15 82 19 17 35 86 40 33 sum=430
// (88, 40, 35, 33, 19) (86, 82, 17, 15,15)
// W1~Wnが乗ってるor乗ってないの計2^n通り
// possibleのとき、仮にW1が左の天秤にあるなら、一意に他のどの重りがどっちに乗ってるか決まる
// 左の天秤にW1がないなら、他の左天秤の重りは、あるときの右天秤と同じもの
//
            
            
            
        