結果

問題 No.4 おもりと天秤
ユーザー siguma323
提出日時 2016-05-05 19:39:22
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 40 ms / 5,000 ms
コード長 1,147 bytes
コンパイル時間 853 ms
コンパイル使用メモリ 93,484 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-26 09:33:00
合計ジャッジ時間 1,882 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <iostream>
#include <queue>
#include <utility>
#include <cmath>
#include <map>
#include <unordered_map>
#include <functional>
#include <fstream>
using namespace std;

using ull = unsigned long long;

int main()
{
    int n;
    cin >> n;
    vector<int> W(n);
    vector<int> all_num;

    for(auto&& x : W)
    {
        cin >> x;
    }

    ull sum = accumulate(W.begin(),W.end(),0);

    if(sum & 1)
    {
        cout << "impossible" << endl;
        return 0;
    }
    else
    {
        sum /=2;
    }

    for(int i = 0; i < n; ++i)
    {
        int max_size = all_num.size();
        for(int j =0; j < max_size; ++j)
        {
            all_num.emplace_back(all_num.at(j) + W.at(i));
        }
        all_num.emplace_back(W.at(i));
        sort(all_num.begin(),all_num.end());
        all_num.erase(unique(all_num.begin(),all_num.end()),all_num.end());
    }

    if(find(all_num.begin(),all_num.end(),sum) != all_num.end())
    {
        cout << "possible" << endl;
    }
    else
    {
        cout << "impossible" << endl;
    }

    return 0;
}
0