結果

問題 No.4 おもりと天秤
ユーザー IrmystpIrmystp
提出日時 2014-11-26 21:22:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 669 bytes
コンパイル時間 1,171 ms
コンパイル使用メモリ 143,596 KB
実行使用メモリ 11,564 KB
最終ジャッジ日時 2023-09-08 16:04:28
合計ジャッジ時間 2,116 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,672 KB
testcase_03 AC 2 ms
4,412 KB
testcase_04 AC 3 ms
4,584 KB
testcase_05 AC 8 ms
11,400 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 8 ms
11,280 KB
testcase_08 AC 8 ms
11,144 KB
testcase_09 AC 8 ms
11,292 KB
testcase_10 AC 9 ms
11,344 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 8 ms
11,484 KB
testcase_19 AC 9 ms
11,392 KB
testcase_20 AC 8 ms
11,336 KB
testcase_21 AC 8 ms
11,344 KB
testcase_22 AC 9 ms
11,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int N;
int w[100];
int arr[101][20001];
int* dp[101];

int main(){
    scanf("%d", &N);
    for(int x = 0; x < N; x++){
        scanf("%d", w+x);
        fill(arr[x], arr[x]+20001, 0);
        dp[x] = arr[x] + 10000;
    }
    dp[N] = arr[N] + 10000;
    dp[0][0] = 1;
    for(int x = 0; x < N; x++){
        for(int y = -10000; y <= 10000; y++){
            if(dp[x][y]){
                dp[x + 1][y + w[x]] = 1;
                dp[x + 1][y - w[x]] = 1;
            }
        }
    }
    if(dp[N][0]){
        puts("possible");
    }else{
        puts("impossible");
    }
    return 0;
}
0