結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  Tatsu_mr | 
| 提出日時 | 2024-10-02 22:00:20 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 7 ms / 5,000 ms | 
| コード長 | 697 bytes | 
| コンパイル時間 | 3,224 ms | 
| コンパイル使用メモリ | 249,308 KB | 
| 実行使用メモリ | 7,168 KB | 
| 最終ジャッジ日時 | 2024-10-02 22:00:25 | 
| 合計ジャッジ時間 | 4,661 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#include <bits/stdc++.h>
#define rep(i, n) for(long long i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using lint = long long;
int main() {
    int n;
    cin >> n;
    vector<int> w(n);
    rep(i, n) {
        cin >> w[i];
    }
    int s = accumulate(ALL(w), 0);
    vector<vector<int>> dp(n + 1, vector<int>(s + 1, false));
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= s; j++) {
            dp[i][j] |= dp[i - 1][j];
            if (j - w[i - 1] >= 0) {
                dp[i][j] |= dp[i - 1][j - w[i - 1]];
            }
        }
    }
    cout << ((s % 2 == 0 && dp[n][s / 2] == 1) ? "possible" : "impossible") << endl;
}
            
            
            
        