結果

問題 No.4 おもりと天秤
ユーザー drymouse
提出日時 2024-02-14 17:46:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 789 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 72,884 KB
最終ジャッジ日時 2025-02-19 13:07:04
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16 WA * 2 TLE * 1 -- * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

bool sum_up_possible(int W[], int tar, int start) {
    if (W[start] > tar) {return false;}
    else if (W[start] == tar) {return true;}
    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