結果

問題 No.4 おもりと天秤
ユーザー kibou1136kibou1136
提出日時 2021-12-08 15:57:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 857 bytes
コンパイル時間 1,623 ms
コンパイル使用メモリ 163,840 KB
実行使用メモリ 398,168 KB
最終ジャッジ日時 2023-09-23 07:11:54
合計ジャッジ時間 8,360 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 226 ms
397,820 KB
testcase_01 AC 227 ms
397,968 KB
testcase_02 AC 228 ms
397,960 KB
testcase_03 AC 228 ms
397,956 KB
testcase_04 AC 229 ms
397,784 KB
testcase_05 WA -
testcase_06 AC 226 ms
398,056 KB
testcase_07 WA -
testcase_08 AC 223 ms
397,784 KB
testcase_09 WA -
testcase_10 AC 247 ms
398,060 KB
testcase_11 AC 248 ms
397,944 KB
testcase_12 AC 231 ms
397,936 KB
testcase_13 AC 243 ms
397,768 KB
testcase_14 AC 227 ms
397,948 KB
testcase_15 AC 236 ms
398,080 KB
testcase_16 AC 226 ms
397,764 KB
testcase_17 AC 224 ms
397,784 KB
testcase_18 AC 225 ms
397,872 KB
testcase_19 WA -
testcase_20 AC 236 ms
397,992 KB
testcase_21 AC 240 ms
398,084 KB
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int n;
int w[101];
int sum;
int dp[101][1000001];



int recu(int N, int W){
    int res = 0;
    if (dp[N][W] > -1) return dp[N][W];
    if (N <= 0 && W > 0){
        dp[N][W] = 0;
        return dp[N][W];
    }
    if (W == 0){
        dp[N][W] = 1;
        return dp[N][W];
    }
    res = recu(N - 1,W);
    if (w[N - 1] <= W){
        res += recu(N - 1, W - w[N - 1]);
    }
    dp[N][W] = res;
    return res;
    
}

int main(){
    memset(dp,-1, sizeof(dp));
    sum = 0;
    dp[0][0] = 1;
    cin >> n;
    for (int i = 0; i < n; ++i){
        cin >> w[i];
        sum += w[i];
    }
    if (sum%2 != 0){
        cout << "impossible" << endl;
        return 0;
    }
    sum = sum/2;
    int res = recu(n, sum);
    if (res > 0) cout << "possible" << endl;
    else cout << "impossible" << endl;
    
}
0