結果

問題 No.4 おもりと天秤
ユーザー nanatutmcnanatutmc
提出日時 2019-10-31 01:21:22
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,131 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 29,432 KB
実行使用メモリ 6,116 KB
最終ジャッジ日時 2023-10-12 23:57:00
合計ジャッジ時間 7,214 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,500 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 0 ms
4,368 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 0 ms
4,368 KB
testcase_07 AC 0 ms
4,372 KB
testcase_08 AC 0 ms
4,372 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,372 KB
testcase_11 AC 1 ms
4,368 KB
testcase_12 AC 0 ms
4,368 KB
testcase_13 AC 1 ms
4,372 KB
testcase_14 AC 1 ms
4,368 KB
testcase_15 AC 1 ms
4,372 KB
testcase_16 WA -
testcase_17 AC 0 ms
4,372 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘main’ 内:
main.c:39:9: 警告: 関数 ‘isPossible’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   39 |     if (isPossible(sum/2, 0, 0) > 0)
      |         ^~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int N;
int W[100];

int main() {
    scanf("%d", &N);
    
    for (int i=0; i<N; i++) {
        scanf("%d", &(W[i]));
    }
    
    int sum = 0;
    for (int i=0; i<N; i++) {
        sum += W[i];
    }
    
    if ((sum % 2) == 1) {
        printf("impossible\n");
        return 0;
    }
    
    // bubble sort
    int flag = 0;
    while (1) {
        flag = 0;
        for (int i=0; i<N-1; i++) {
            if (W[i] < W[i+1]) {
                int tmp = W[i];
                W[i] = W[i+1];
                W[i+1] = tmp;
                flag = 1;
            }
        }
        if (flag == 0)
            break;
    }

    if (isPossible(sum/2, 0, 0) > 0)
        printf("possible\n");
    else
        printf("impossible\n");
}

int isPossible(int target, int weight, int pos) {
    int curWeight = weight + W[pos];

    if (target == curWeight)
        return 1;

    if (pos == N-1)
        return 0;

    if (target < curWeight)
        return 0;

    if (isPossible(target, curWeight, pos+1) > 0)
        return 1;
    if (isPossible(target, weight, pos+1) > 0)
        return 1;

    return 0;
}
0