結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-02-14 18:12:59 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                RE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 811 bytes | 
| コンパイル時間 | 1,046 ms | 
| コンパイル使用メモリ | 72,376 KB | 
| 最終ジャッジ日時 | 2025-02-19 13:07:50 | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 11 RE * 12 | 
ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
bool sum_up_possible(int W[], int tar, int start) {
    if (tar == 0) {return true;}
    else if (W[start] > tar) {return sum_up_possible(W, tar, start + 1);}
    return sum_up_possible(W, tar - W[start], start + 1) ||
    sum_up_possible(W, tar, start + 1);
}
int main(void) {
    int N;
    cin >> N;
    int W[N];
    int sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> W[i];
        sum += W[i];
    }
    //cout << "sum: " << sum << endl;
    if (sum % 2) {
        cout << "impossible" << endl;
    } else {
        sort(W, W + N, greater<int>());
        if (sum_up_possible(W, sum / 2 - W[0], 1)) {
            cout << "possible" << endl;
        } else {
            cout << "impossible" << endl;
        }
    }
    return 0;
}
            
            
            
        