結果

問題 No.4 おもりと天秤
ユーザー rgnerdplayer
提出日時 2024-02-14 02:18:32
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 730 bytes
コンパイル時間 2,934 ms
コンパイル使用メモリ 246,292 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-09-28 18:42:21
合計ジャッジ時間 3,706 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    auto solve = [&]() {
        int n;
        cin >> n;

        vector<int> w(n);
        for (int i = 0; i < n; i++) {
            cin >> w[i];
        }

        int V = accumulate(w.begin(), w.end(), 0);
        if (V % 2 == 1) {
            cout << "impossible\n";
            return;
        }

        vector<int> dp(V + 1);
        dp[0] = true;

        for (auto w : w) {
            for (int i = V; i >= w; i--) {
                dp[i] |= dp[i - w];
            }
        }

        cout << (dp[V / 2] ? "possible" : "impossible") << '\n';
    };
    
    solve();
    
    return 0;
}
0