結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  🍮かんプリン | 
| 提出日時 | 2019-04-18 12:24:44 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 1,371 bytes | 
| コンパイル時間 | 689 ms | 
| コンパイル使用メモリ | 79,744 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-09-22 09:09:33 | 
| 合計ジャッジ時間 | 1,482 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <set>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define P pair<int, int>
#define MOD 1000000007
#define INF 2147483647
#define NINF (-2147483647-1)
#define LLINF 9223372036854775807
using ll = long long;
using namespace std;
int main() {
    int N, sum = 0;
    cin >> N;
    vector<int> W(N);
    for (int i = 0; i < N; i++)
    {
        cin >> W[i];
        sum += W[i];
    }
    if (sum % 2 == 0) {
        sum /= 2;
        // dp[i][j] := i番目までの数字を使ってjが作れるか
        vector<vector<bool>> dp(N+1, vector<bool>(sum + 1, false));
        dp[0][0] = true;
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j <= sum; j++)
            {
                if (dp[i][j]) {
                    dp[i + 1][j] = true;
                }
                if (j + W[i] <= sum && dp[i][j]) {
                    dp[i + 1][j + W[i]] = true;
                }
            }
        }
        if (dp[N][sum]) {
            cout << "possible" << endl;
        }
        else {
            cout << "impossible" << endl;
        }
    }
    else {
        cout << "impossible" << endl;
    }
    getchar(); getchar();
    return 0;
}
            
            
            
        