結果

問題 No.4 おもりと天秤
ユーザー suakii
提出日時 2019-04-18 12:01:35
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 853 bytes
コンパイル時間 1,279 ms
コンパイル使用メモリ 159,532 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-22 09:09:25
合計ジャッジ時間 2,076 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int n;
ll sum;
int w[10001];
bool dp[100][10001];
bool f(int index, int weight) {

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

    return dp[index][weight] = 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;
    }
    dp[0][0] = true;
    if (f(0,0)) {
        cout << "possible\n";
    } else {
        cout << "impossible\n";
    }
    








    return 0;
}

0