結果

問題 No.4 おもりと天秤
ユーザー drymousedrymouse
提出日時 2024-02-14 18:12:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 811 bytes
コンパイル時間 1,024 ms
コンパイル使用メモリ 74,380 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-14 18:13:03
合計ジャッジ時間 3,814 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 2 ms
6,676 KB
testcase_06 RE -
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 2 ms
6,676 KB
testcase_18 RE -
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0