結果

問題 No.4 おもりと天秤
ユーザー suakiisuakii
提出日時 2019-04-18 12:01:35
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 853 bytes
コンパイル時間 1,610 ms
コンパイル使用メモリ 158,800 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 08:08:01
合計ジャッジ時間 2,591 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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