結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-05-19 12:10:47 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 775 bytes | 
| コンパイル時間 | 708 ms | 
| コンパイル使用メモリ | 71,516 KB | 
| 実行使用メモリ | 10,144 KB | 
| 最終ジャッジ日時 | 2024-09-18 22:43:46 | 
| 合計ジャッジ時間 | 7,507 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 15 WA * 3 TLE * 1 -- * 4 | 
ソースコード
#include <iostream>
#include <vector>
#include <numeric>
int N;
std::vector<int> W;
bool check(int ind, int t) {
    if (t == 0) {
        return true;
    } else if (t < 0) {
        return false;
    }
    for (int i = ind; i < N; i++) {
        if (check(i, t - W[i])) {
            return true;
        }
    }
    return false;
}
int main() {
    int sum;
    int target;
    std::cin >> N;
    W.resize(N);
    for (int i = 0; i < N; i++) {
        std::cin >> W[i];
    }
    sum = std::accumulate(W.begin(), W.end(), 0);
    target = sum / 2;
    if (sum % 2 == 1) {
        std::cout << "impossible" << std::endl;
    } else if (check(0, target)) {
        std::cout << "possible" << std::endl;
    } else {
        std::cout << "impossible" << std::endl;
    }
}
            
            
            
        