結果

問題 No.4 おもりと天秤
ユーザー cherrypi59cherrypi59
提出日時 2018-10-11 08:49:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 648 bytes
コンパイル時間 1,586 ms
コンパイル使用メモリ 167,176 KB
実行使用メモリ 7,320 KB
最終ジャッジ日時 2023-08-02 19:32:14
合計ジャッジ時間 2,586 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

const int MAX_N = 100, MAX_SUM = 10000;
int dp[MAX_N+1][MAX_SUM+1];

int main(){
    int n, sw = 0; cin>>n;
    vector<int> w(n);
    for(int i=0;i<n;i++){
        cin>>w[i];
        sw += w[i];
    }

    if(sw%2){
        cout<<"impossible"<<endl;
        return 0;
    }

    dp[0][0] = 1;
    for(int i=1;i<=n;i++){
        for(int j=w[i-1];j<=sw;j++){
            dp[i][j] += dp[i-1][j-w[i-1]] + dp[i-1][j];
        }
    }

    for(int i=1;i<=n;i++){
        if(dp[i][sw/2]){
            cout<<"possible"<<endl;
            return 0;
        }
    }

    cout<<"impossible"<<endl;
    return 0;
}
0