結果

問題 No.4 おもりと天秤
ユーザー dsytk7dsytk7
提出日時 2018-02-14 22:39:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 822 bytes
コンパイル時間 4,332 ms
コンパイル使用メモリ 164,072 KB
実行使用メモリ 7,652 KB
最終ジャッジ日時 2023-08-24 22:04:59
合計ジャッジ時間 4,202 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,512 KB
testcase_01 AC 5 ms
7,432 KB
testcase_02 AC 5 ms
7,364 KB
testcase_03 AC 4 ms
7,364 KB
testcase_04 AC 4 ms
7,376 KB
testcase_05 RE -
testcase_06 AC 4 ms
7,424 KB
testcase_07 RE -
testcase_08 AC 5 ms
7,360 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 5 ms
7,516 KB
testcase_12 AC 4 ms
7,412 KB
testcase_13 AC 5 ms
7,652 KB
testcase_14 AC 4 ms
7,440 KB
testcase_15 AC 4 ms
7,376 KB
testcase_16 AC 4 ms
7,416 KB
testcase_17 AC 5 ms
7,636 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
権限があれば一括ダウンロードができます

ソースコード

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[101][101][101];
int N;
int W[101];

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

int main() {
    cin >> N;
    rep(i, N) cin >> W[i];
    rep(i, 101) rep(j, 101) rep(k, 101) dp[i][j][k] = -1;
    cout << (solve(0, 0, 0) == 1 ? pos : imp) << endl;
    return 0;
}
0