結果

問題 No.4 おもりと天秤
ユーザー starHo4starHo4
提出日時 2021-08-10 21:44:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 792 bytes
コンパイル時間 762 ms
コンパイル使用メモリ 74,756 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-24 06:36:06
合計ジャッジ時間 2,557 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> W(N);
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> W[i];
        sum += W[i];
    }
    if (sum % 2)
    {
        cout << "impossible" << endl;
        return 0;
    }
    sum /= 2;
    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])
            {
                continue;
            }
            dp[i + 1][j] = true;
            dp[i + 1][j + W[i]] = true;
        }
    }
    if (dp[N][sum])
    {
        cout << "possible" << endl;
    }
    else
    {
        cout << "impossible" << endl;
    }
}
0