結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-02-25 17:23:59 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                RE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 647 bytes | 
| コンパイル時間 | 1,723 ms | 
| コンパイル使用メモリ | 169,104 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-10-13 12:24:32 | 
| 合計ジャッジ時間 | 3,084 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 14 WA * 5 RE * 4 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin >> n;
    vector<int> w(n);
    bool dp[n+1][1001];
    int sum=0;
    for(int i=0;i<n;i++){
        cin >> w[i];
        sum+=w[i];
    }
    if(sum%2==1){
        cout << "impossible" << endl;
        return 0;
    }
    memset(dp,false,sizeof(dp));
    dp[0][0]=true;
    for(int i=0;i<n;i++){
        for(int j=0;j<1001;j++){
            if(dp[i][j]){
                dp[i+1][j]=true;
                dp[i+1][j+w[i]]=true;
            }
        }
    }
    if(dp[n][sum/2]){
        cout << "possible" << endl;
    }
    else{
        cout << "impossible" << endl;
    }
}
            
            
            
        