結果

問題 No.4 おもりと天秤
ユーザー kroton
提出日時 2014-11-01 05:44:09
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 648 bytes
コンパイル時間 683 ms
コンパイル使用メモリ 54,396 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-30 15:52:00
合計ジャッジ時間 1,495 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20 WA * 3
権限があれば一括ダウンロードができます

ソースコード

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<=w_sum;sum++){
                dp[sum] |= dp[sum-w];
            }
        }
        
        cout << (dp[w_sum] ? "possible" : "impossible") << endl;
    }
    
    return 0;
}
0