結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  ama_nuko | 
| 提出日時 | 2018-06-14 01:54:36 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 4 ms / 5,000 ms | 
| コード長 | 920 bytes | 
| コンパイル時間 | 815 ms | 
| コンパイル使用メモリ | 97,512 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-30 14:17:30 | 
| 合計ジャッジ時間 | 1,609 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>
#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int, int> P;
const int INF = 1e15;
const int MOD = 1e9+7;
signed main(){
    int n;
    cin >> n;
    vector<int> w(n);
    rep(i, n) cin >> w[i];
    vector<bool> dp(10001, false);
    dp[0] = true;
    rep(i, n){
        for(int j = 10000; j >= 1; j--){
            if(j < w[i]){
                continue;
            }
            dp[j] = dp[j] || dp[j-w[i]];
        }
    }
    int sum = 0;
    rep(i, n) sum += w[i];
    if(sum % 2 == 1){
        cout << "impossible" << endl;
        return 0;
    }
    sum /= 2;
    if(dp[sum]){
        cout << "possible" << endl;
    }else{
        cout << "impossible" << endl;
    }
    return 0;
}
            
            
            
        