結果

問題 No.4 おもりと天秤
コンテスト
ユーザー halship
提出日時 2017-06-29 17:40:54
言語 C++11
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
RE  
実行時間 -
コード長 609 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 352 ms
コンパイル使用メモリ 79,592 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-09-10 06:02:12
合計ジャッジ時間 2,366 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 RE * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
#define REP(i, N) for(int i=0;i<(N);++i)

int main() {
    int n; cin >> n;
    vector<int> ws(n); REP(i, n) cin >> ws[i];
    int sum = accumulate(ws.begin(), ws.end(), 0);
    if (sum % 2 == 1) {
        cout << "impossible" << endl;
        return 0;
    }

    int half = sum / 2;
    vector<bool> memo(half+1, false);
    memo[0] = true;
    for (int w : ws) {
        for (int i = half; i >= 0; --i) if(memo[i]) memo[i+w] = true;
    }

    if (memo[half]) cout << "possible" << endl;
    else cout << "impossible" << endl;
}
0