結果

問題 No.4 おもりと天秤
ユーザー mlpj56d
提出日時 2018-08-18 06:31:23
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 487 bytes
コンパイル時間 373 ms
コンパイル使用メモリ 55,208 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-12 22:32:53
合計ジャッジ時間 1,143 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 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];
    }
    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