結果

問題 No.4 おもりと天秤
ユーザー halshiphalship
提出日時 2017-06-29 17:40:54
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 609 bytes
コンパイル時間 649 ms
コンパイル使用メモリ 61,392 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 04:55:04
合計ジャッジ時間 1,970 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 RE -
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 RE -
testcase_06 AC 2 ms
6,944 KB
testcase_07 RE -
testcase_08 AC 1 ms
6,940 KB
testcase_09 RE -
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 RE -
testcase_17 AC 2 ms
6,944 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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