結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  Kutimoti_T | 
| 提出日時 | 2017-12-17 16:05:49 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 4 ms / 5,000 ms | 
| コード長 | 858 bytes | 
| コンパイル時間 | 565 ms | 
| コンパイル使用メモリ | 72,756 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-26 10:25:23 | 
| 合計ジャッジ時間 | 1,325 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define FOR(i,s,e) for(int i = (s);i <= (e);i++)
vector<vector<bool>> dp(101,vector<bool>(10100,false));
int W[101];
int N;
int total = 0;
int main()
{
    cin >> N;
    FOR(i,0,N - 1)
    {
        cin >> W[i];
        total += W[i];
    }
    if(total % 2 == 1)
    {
        cout << "impossible" << endl;
        return 0;
    }
    dp[0][0] = true;
    FOR(i,0,N - 1)
    {
        FOR(j,0,5049)
        {
            dp[i + 1][j] = dp[i][j] || dp[i + 1][j];
            if(dp[i][j] && j + W[i] <= 10000)
            {
                dp[i + 1][j + W[i]] = true;
            }
        }
    }
    if(dp[N][total / 2]) cout << "possible" << endl;
    else cout << "impossible" << endl;
    return 0;
}
            
            
            
        