結果

問題 No.4 おもりと天秤
コンテスト
ユーザー halship
提出日時 2017-06-29 17:48:18
言語 C++11
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 5,000 ms
+ 544µs
コード長 636 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 336 ms
コンパイル使用メモリ 79,076 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-30 12:01:21
合計ジャッジ時間 1,781 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

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(10000, 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