結果

問題 No.4 おもりと天秤
ユーザー suakii
提出日時 2019-04-18 11:59:04
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 685 bytes
コンパイル時間 1,200 ms
コンパイル使用メモリ 158,748 KB
実行使用メモリ 10,140 KB
最終ジャッジ日時 2024-09-22 09:09:22
合計ジャッジ時間 7,712 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n;
ll sum;
int w[10001];

bool f(int index, int weight) {

    if (weight == sum / 2)
        return true;
    if (weight > sum/2)
        return false;
    if (index == n)
        return false;

    return f(index+1, weight) || f(index+1, weight + w[index]);
}

int main() {
    ios::sync_with_stdio(false);
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> w[i];
        sum += w[i];
    }
    if (sum & 1) {
        cout << "impossible\n";
        return 0;
    }

    if (f(0,0)) {
        cout << "possible\n";
    } else {
        cout << "impossible\n";
    }
    








    return 0;
}

0