結果

問題 No.4 おもりと天秤
ユーザー kroton
提出日時 2014-11-28 18:56:31
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 648 bytes
コンパイル時間 436 ms
コンパイル使用メモリ 55,848 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-26 09:04:23
合計ジャッジ時間 1,234 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

bool dp[5010];
int W[111];

int main(){
    int N;
    cin >> N;
    
    int w_sum = 0;
    for(int i=0;i<N;i++){
        cin >> W[i];
        w_sum += W[i];
    }
    
    if(w_sum % 2 != 0){
        cout << "impossible" << endl;
    } else {
        w_sum /= 2;
        dp[0] = true;
        
        for(int i=0;i<N;i++){
            int w = W[i];
            
            for(int sum=w_sum;sum>=w;sum--){
                dp[sum] |= dp[sum-w];
            }
        }
        
        cout << (dp[w_sum] ? "possible" : "impossible") << endl;
    }
    
    return 0;
}
0