結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2014-12-09 22:49:15 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 1,061 bytes | 
| コンパイル時間 | 808 ms | 
| コンパイル使用メモリ | 93,632 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-26 09:04:27 | 
| 合計ジャッジ時間 | 1,518 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;
bool solve(const vector<int>& w)
{
    int n = w.size();
    int sum = accumulate(w.begin(), w.end(), 0);
    if(sum % 2 != 0)
        return false;
    int half = sum / 2;
    vector<bool> dp(half + 1, false);
    dp[0] = true;
    for(int i=0; i<n; ++i){
        for(int j=half-w[i]; j>=0; --j){
            if(dp[j])
                dp[j+w[i]] = true;
        }
    }
    return dp[half];
}
int main()
{
    int n;
    cin >> n;
    vector<int> w(n);
    for(int i=0; i<n; ++i)
        cin >> w[i];
    if(solve(w))
        cout << "possible" << endl;
    else
        cout << "impossible" << endl;
    return 0;
}
            
            
            
        