結果

問題 No.4 おもりと天秤
ユーザー mlpj56d
提出日時 2018-08-18 06:30:46
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 512 bytes
コンパイル時間 568 ms
コンパイル使用メモリ 55,204 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-12 22:32:32
合計ジャッジ時間 1,328 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<iostream>

using namespace std;

int N;
int W[110];
int dp[10210];
int main(){
    cin >> N;
    int sum = 0;
    for(int i=0; i<N; i++) {
        cin >> W[i];
        sum += W[i];
    }
    cout << sum << endl;
    dp[0] = 1;
    for(int i=0; i<N; i++){
        for(int j=10000; j>=W[i]; j--){
            if( dp[j-W[i]] > 0 ) dp[j] = dp[j-W[i]] + 1;
        }
    }
    if( sum % 2 || dp[sum/2] < 1) cout << "impossible" << endl;
    else cout << "possible" << endl;
    return 0;
}
0