結果

問題 No.4 おもりと天秤
ユーザー dsytk7dsytk7
提出日時 2018-02-14 22:50:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 894 bytes
コンパイル時間 1,502 ms
コンパイル使用メモリ 164,572 KB
実行使用メモリ 7,700 KB
最終ジャッジ日時 2023-09-08 17:40:12
合計ジャッジ時間 2,444 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 6 ms
7,488 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 7 ms
7,464 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 4 ms
7,468 KB
testcase_10 AC 7 ms
7,500 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 5 ms
7,468 KB
testcase_19 AC 6 ms
7,468 KB
testcase_20 AC 6 ms
7,572 KB
testcase_21 AC 6 ms
7,528 KB
testcase_22 AC 6 ms
7,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

string pos = "possible", imp = "impossible";
int dp[110][10010];
int N, sum;
int W[101];

int solve(int idx, int l) {
    int& res = dp[idx][l];
    if (~res) return res;
    if (sum/2 == l) {
        res = 1;
    }
    else if (idx >= N) {
        res = 0;
    }
    else {
        res = max(solve(idx+1, l), solve(idx+1, l+W[idx]));
    }
    return res;
}

int main() {
    cin >> N;
    rep(i, N) cin >> W[i], sum += W[i];
    if (sum%2) {
        cout << imp << endl;
        return 0;
    }
    fill(dp[0], dp[N], -1);
    cout << (solve(0, 0) == 1 ? pos : imp) << endl;
    return 0;
}
0