結果

問題 No.4 おもりと天秤
ユーザー fushime2fushime2
提出日時 2017-12-29 20:22:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 493 bytes
コンパイル時間 1,439 ms
コンパイル使用メモリ 146,056 KB
実行使用メモリ 7,824 KB
最終ジャッジ日時 2023-09-08 17:37:58
合計ジャッジ時間 2,306 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,696 KB
testcase_01 AC 4 ms
7,576 KB
testcase_02 AC 3 ms
7,704 KB
testcase_03 AC 4 ms
7,552 KB
testcase_04 AC 4 ms
7,708 KB
testcase_05 AC 6 ms
7,628 KB
testcase_06 AC 3 ms
7,628 KB
testcase_07 AC 7 ms
7,580 KB
testcase_08 AC 4 ms
7,644 KB
testcase_09 AC 4 ms
7,648 KB
testcase_10 AC 7 ms
7,820 KB
testcase_11 AC 4 ms
7,620 KB
testcase_12 AC 4 ms
7,824 KB
testcase_13 AC 4 ms
7,576 KB
testcase_14 AC 4 ms
7,780 KB
testcase_15 AC 4 ms
7,776 KB
testcase_16 AC 4 ms
7,764 KB
testcase_17 AC 4 ms
7,624 KB
testcase_18 AC 5 ms
7,560 KB
testcase_19 AC 7 ms
7,632 KB
testcase_20 AC 6 ms
7,700 KB
testcase_21 AC 6 ms
7,712 KB
testcase_22 AC 7 ms
7,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define mset(a,x) memset(a,x,sizeof(a))

int N;
vector<int> W;
int sum = 0;

int dp[110][10010];
bool rec(int i, int w) {
    int &r = dp[i][w];
    if (r != -1) return r;
    if (i >= N) return r = (w == sum - w);
    return r = rec(i + 1, w) | rec(i + 1, w + W[i]);
}

int main() {
    cin >> N; W.resize(N);
    for (int& i : W) cin >> i, sum += i;
    mset(dp, -1);
    cout << (rec(0, 0) ? "possible" : "impossible") << endl;
    return 0;
}
0