結果

問題 No.4 おもりと天秤
ユーザー Kutimoti_TKutimoti_T
提出日時 2017-12-17 16:03:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 863 bytes
コンパイル時間 893 ms
コンパイル使用メモリ 82,708 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-09 10:22:34
合計ジャッジ時間 3,919 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 RE -
testcase_06 WA -
testcase_07 RE -
testcase_08 WA -
testcase_09 RE -
testcase_10 RE -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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(100,vector<bool>(5050,false));

int W[101];

int N;
int total = 0;

int main()
{
    cin >> N;
    FOR(i,0,N - 1)
    {
        cin >> W[i];
        total += W[i];
    }
    cout << total << endl;
    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])
            {
                dp[i + 1][j + W[i]] = true;
            }
        }
    }

    if(dp[N][total / 2]) cout << "possible" << endl;
    else cout << "impossible" << endl;
    return 0;
}
0