結果

問題 No.4 おもりと天秤
ユーザー くれちーくれちー
提出日時 2017-03-15 22:23:15
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,713 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 30,420 KB
実行使用メモリ 46,584 KB
最終ジャッジ日時 2023-09-17 03:42:38
合計ジャッジ時間 1,303 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
46,572 KB
testcase_01 AC 12 ms
46,452 KB
testcase_02 AC 11 ms
46,544 KB
testcase_03 AC 13 ms
46,456 KB
testcase_04 AC 13 ms
46,516 KB
testcase_05 AC 13 ms
46,524 KB
testcase_06 AC 12 ms
46,420 KB
testcase_07 AC 12 ms
46,504 KB
testcase_08 AC 12 ms
46,564 KB
testcase_09 AC 12 ms
46,456 KB
testcase_10 AC 13 ms
46,456 KB
testcase_11 AC 13 ms
46,500 KB
testcase_12 AC 12 ms
46,432 KB
testcase_13 AC 12 ms
46,512 KB
testcase_14 AC 12 ms
46,420 KB
testcase_15 AC 13 ms
46,500 KB
testcase_16 AC 13 ms
46,488 KB
testcase_17 AC 12 ms
46,392 KB
testcase_18 WA -
testcase_19 AC 12 ms
46,584 KB
testcase_20 AC 12 ms
46,580 KB
testcase_21 AC 12 ms
46,508 KB
testcase_22 AC 12 ms
46,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REP1(i, n) for (ll i = 1; i <= n; i++)
#define RREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define RREP1(i, n) for (ll i = n; i >= 1; i--)
#define FOR(i, a, b, c) for (ll i = a; i <= b; i += c)
#define RFOR(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)
#define SORT(t, a, n) qsort(a, n, sizeof(t), ({ int _f (const void *_a, const void *_b) { return *(t *)_a - *(t *)_b; } _f; }))
#define RSORT(t, a, n) qsort(a, n, sizeof(t), ({ int _f (const void *_a, const void *_b) { return *(t *)_b - *(t *)_a; } _f; }))
#define SUM(a, n) ({ ll _s = 0; REP(_i, n) _s += a[_i]; _s; })
#define CNT(x, a, n) ({ ll _c = 0; REP(_i, n) if (a[_i] == x) _c++; _c; })
#define MAXM(t, a, n) ({ t _m = a[0]; REP(_i, n) _m = MAX(_m, a[_i]); _m; })
#define MINM(t, a, n) ({ t _m = a[0]; REP(_i, n) _m = MIN(_m, a[_i]); _m; })
#define INF 1145141919
typedef long long ll;

int n, w[100], ws;
int dp[100][114514];

bool dfs(int idx, int sum) {
    if (dp[idx][sum] != -1)
        return dp[idx][sum];
    if (idx == n) 
        return dp[idx][sum] = sum == ws / 2;
    if (sum + (n - idx) > ws / 2)
        return dp[idx][sum] = false;
    if (dfs(idx + 1, sum))
        return dp[idx][sum] = true;
    if (dfs(idx + 1, sum + w[idx]))
        return dp[idx][sum] = true;
    return dp[idx][sum] = false;
}

int main() {
    scanf("%d", &n);
    REP(i, n) scanf("%d", &w[i]);
    ws = SUM(w, n);
    memset(dp, -1, sizeof(dp));
    
    if (ws % 2 || !dfs(0, 0)) puts("impossible");
    else puts("possible");
    return 0;
}
0