結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  dazy | 
| 提出日時 | 2017-11-25 04:33:29 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 869 bytes | 
| コンパイル時間 | 574 ms | 
| コンパイル使用メモリ | 56,260 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-26 10:24:32 | 
| 合計ジャッジ時間 | 1,269 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#include <iostream>
using namespace std;
#define fastcin {\
    cin.tie(0);\
    ios::sync_with_stdio(false);\
}
#define scan(x) cin >> x
#define print(x) cout << x << "\n"
int main() {
    fastcin;
    int n, i, j;
    scan(n);
    int sum = 0, w[n];
    for (i = 0; i < n; ++i) {
        scan(w[i]);
        sum += w[i];
    }
    if ((sum & 0x01)) {
        print("impossible");
    } else {
        int half = sum/2;
        bool dp[n+1][half+1];
        for (i = 0; i < n+1; ++i) for (j = 0; j < half+1; ++j) dp[i][j] = false;
        dp[0][0] = true;
        for (i = 0; i < n; ++i) {
            for (j = 0; j < half+1; ++j) {
                dp[i+1][j] |= dp[i][j];
                if (j+w[i] <= half) dp[i+1][j+w[i]] |= dp[i][j];
            }
        }
        if (dp[n][half]) print("possible");
        else print("impossible");
    }
    return 0;
}
            
            
            
        