結果

問題 No.4 おもりと天秤
ユーザー cleasky
提出日時 2023-06-04 14:15:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 622 bytes
コンパイル時間 1,908 ms
コンパイル使用メモリ 192,256 KB
最終ジャッジ日時 2025-02-13 22:38:26
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

    int N;
    cin >> N;

    int weight[10006];
    int sum = 0;
    for (int i = 1; i <= N; i++) {
        cin >> weight[i];
        sum += weight[i];
    }

    bool dp[10006];
    dp[0] = true;

    for (int i = 1; i <= N; i++) {
        for (int j = 10000; j >= 0; j--) {
            if (dp[j]) {
                dp[j + weight[i]] = true;
            }
        }
    }

    if (sum % 2 == 0 and dp[sum / 2]) {
        cout << "possible" << endl;
    } else {
        cout << "impossible" << endl;
    }

    return 0;
}
0