結果

問題 No.4 おもりと天秤
ユーザー heabiheabi
提出日時 2020-11-21 12:33:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,966 bytes
コンパイル時間 1,502 ms
コンパイル使用メモリ 169,732 KB
実行使用メモリ 11,200 KB
最終ジャッジ日時 2023-09-30 21:43:37
合計ジャッジ時間 2,565 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
#define vvvvll vector<vector<vector<vector<ll>>>>
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>

constexpr ll INF = (1ll << 60);
constexpr ll mod = 1000000007;  // 998244353;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

void pt_vvll(vvll v) {
    ll vs = v.size(), vs0 = v[0].size();
    rep(i, vs) {
        rep(j, vs0) {
            cout << v[i][j];

            if (j != vs0 - 1)
                cout << " ";
            else
                cout << "\n";
        }
    }
}
void pt_vll(vll v) {
    ll vs = v.size();
    rep(i, vs) {
        cout << v[i];
        if (i == vs - 1)
            cout << "\n";
        else
            cout << " ";
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N;
    cin >> N;
    vll W(N);
    ll sum = 0;
    rep(i, N) {
        cin >> W[i];
        sum += W[i];
    }
    if (sum % 2) {
        cout << "impossible\n";
        return 0;
    }

    vvll dp(N + 1, vll(1e4 + 10));
    dp[0][0] = 1;

    rep(i, N) {
        rep(j, 1e4 + 10) {
            if (dp[i][j]) {
                dp[i + 1][j + W[i]] = 1;
            }
        }
    }
    bool ans = false;
    rep(i, N) rep(j, 1e4 + 10) {
        if (dp[i][j] && j == sum / 2) {
            ans = true;
            break;
        }
    }

    if (ans)
        cout << "possible\n";
    else
        cout << "impossible\n";
    return 0;
}
0