結果

問題 No.4 おもりと天秤
ユーザー coco18000coco18000
提出日時 2019-12-12 22:35:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 789 bytes
コンパイル時間 1,530 ms
コンパイル使用メモリ 165,436 KB
実行使用メモリ 4,520 KB
最終ジャッジ日時 2023-09-08 02:22:05
合計ジャッジ時間 2,611 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll W[105];
bool dp[105][10005];

int main() {
    ll N;
    cin >> N;
    ll sum = 0;
    REP(i, N) {
        cin >> W[i];
        sum += W[i];
    }
    memset(dp, 0, sizeof(dp));
    dp[0][0] = true;
    REP(i, N) {
        REP(j, sum) {
            if (dp[i][j]) {
                dp[i + 1][j + W[i]] = true;
                dp[i + 1][j] = true;
            }
        }
    }

    if (sum % 2 == 0 && dp[N][sum / 2])
        cout << "possible" << endl;
    else
        cout << "impossible" << endl;
    return 0;
}
0