結果

問題 No.4 おもりと天秤
コンテスト
ユーザー himueu
提出日時 2026-10-15 15:59:53
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
+ 416µs
コード長 661 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,770 ms
コンパイル使用メモリ 178,376 KB
実行使用メモリ 9,868 KB
最終ジャッジ日時 2026-10-15 15:59:58
合計ジャッジ時間 4,552 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>

int main() {
    using namespace std;
    int n, tot = 0;
    cin >> n;
    vector<int> w(n);
    for (auto &e : w) {
        cin >> e;
        tot += e;
    }

    if (tot % 2 > 0) {
        cout << "impossible\n";
        return 0;
    }

    const int m = tot / 2;
    vector dp(n + 1, vector<bool>(m + 1, false));
    dp[0][0] = true;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= m; j++) {
            if (!dp[i][j]) { continue; }
            dp[i + 1][j] = true;
            if (j + w[i] <= m) { dp[i + 1][j + w[i]] = true; }
        }
    }
    cout << (dp[n][m] ? "possible\n" : "impossible\n");
}
0