結果

問題 No.4 おもりと天秤
ユーザー cherrypi59cherrypi59
提出日時 2018-10-11 08:49:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 648 bytes
コンパイル時間 1,468 ms
コンパイル使用メモリ 164,348 KB
実行使用メモリ 7,464 KB
最終ジャッジ日時 2024-04-20 19:40:24
合計ジャッジ時間 2,214 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 4 ms
6,016 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 4 ms
6,144 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 4 ms
7,464 KB
testcase_10 AC 4 ms
6,272 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 4 ms
6,144 KB
testcase_19 AC 3 ms
5,888 KB
testcase_20 AC 4 ms
5,760 KB
testcase_21 AC 3 ms
5,632 KB
testcase_22 AC 4 ms
5,760 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