結果

問題 No.4 おもりと天秤
ユーザー tadanoningentadanoningen
提出日時 2020-10-01 23:56:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 667 bytes
コンパイル時間 622 ms
コンパイル使用メモリ 72,456 KB
実行使用メモリ 5,256 KB
最終ジャッジ日時 2023-09-21 17:21:23
合計ジャッジ時間 3,392 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>

using namespace std;

vector<vector<bool>> dp(101,vector<bool>(10001,false));

int main(){
    int n,sum = 0;
    cin >> n;
    int w[n];
    for(int i=0;i < n;i++){
        cin >> w[i];
        sum += w[i];
    }
    if(sum % 2 == 1) {
        cout << "impossible" << endl;
        return 0;
    }

    dp[0][0] = true;

    for(int i=0;i <= n;i++){
        for(int j=0;j < 10000;j++){
            if(dp[i][j] == true){
                dp[i+1][j+w[i]] = true;
                dp[i+1][j] = true;
            }
        }
    }

    if(dp[n][sum/2]) cout << "possible" << endl;
    else cout << "impossible" << endl;
    return 0;
}
0