結果

問題 No.4 おもりと天秤
ユーザー heabiheabi
提出日時 2020-11-21 12:39:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 1,880 bytes
コンパイル時間 1,591 ms
コンパイル使用メモリ 170,484 KB
実行使用メモリ 11,092 KB
最終ジャッジ日時 2023-09-30 21:43:46
合計ジャッジ時間 2,609 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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];
    }

    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;
                dp[i + 1][j] = 1;
            }
        }
    }

    rep(i, N + 1) rep(j, 1e4 + 10) {
        if (dp[i][j] && j == sum / 2 && sum % 2 == 0) {
            cout << "possible\n";
            return 0;
        }
    }

    cout << "impossible\n";
    return 0;
}
0