結果

問題 No.4 おもりと天秤
ユーザー nanatutmcnanatutmc
提出日時 2019-11-01 00:40:57
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 1,078 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 29,632 KB
実行使用メモリ 6,000 KB
最終ジャッジ日時 2023-10-13 00:15:52
合計ジャッジ時間 7,062 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 0 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 0 ms
4,352 KB
testcase_09 AC 0 ms
4,352 KB
testcase_10 AC 0 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 0 ms
4,352 KB
testcase_15 AC 0 ms
4,352 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 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-W[0], 1))
      |         ^~~~~~~~~~

ソースコード

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-W[0], 1))
        printf("possible\n");
    else
        printf("impossible\n");
}

int isPossible(int target, int pos) {

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

    if (target < W[pos])
        return isPossible(target, pos+1);

    if (isPossible(target-W[pos], pos+1) > 0)
        return 1;
    if (isPossible(target, pos+1) > 0)
        return 1;

    return 0;
}
0