結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-11-16 13:52:18 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,408 bytes | 
| コンパイル時間 | 470 ms | 
| コンパイル使用メモリ | 58,664 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-09-24 23:19:31 | 
| 合計ジャッジ時間 | 1,230 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 10 WA * 13 | 
ソースコード
//#include <bits/stdc++.h>
//#include "includes.h"
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
#define INF 10000000000000
int main() {
    long long b, c, n, m;
    long long k1, k2;
    long long s = 0;
    cin >> n;
    long long w[n];
    for(int i=0;i<n;i++) {
        cin >> b;
        s += b;
        w[i] = b;
    }
    if(s%2 != 0) {
        cout << "impossible" << endl;
        return 0;
    } else {
        m = b/2;
    }
    //cout << "A" << endl;
    int dp[n+1][m+1];
    for(int i=0;i<m+1;i++) {
        dp[0][i] = 0;
    }
    //cout << "B" << endl;
    //cout << "C" << endl;
    for(int i=0;i<n;i++) {
        for(int j=0;j<m+1;j++) {
            if (j >= w[i]) {
                k1 = dp[i][j];
                k2 = dp[i][j-w[i]] + 1;
                if(k1 == m || k2 == m) {
                    cout << "possible" << endl;
                    return 0;
                }
                dp[i+1][j] = max(k1, k2);
            } else {
                if (dp[i][j] == m) {
                    cout << "possible" << endl;
                    return 0;
                }
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    //cout << "D" << endl;
    //for(int i=0;i<n+1;i++) {
    //    for(int j=0;j<m+1;j++) {
    //        cout << dp[i][j] << " ";
    //    }
    //    cout << endl;
    //}
    cout << "impossible" << endl;
}
            
            
            
        