結果

問題 No.4 おもりと天秤
ユーザー roaiziroroaiziro
提出日時 2015-09-25 15:59:43
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 905 bytes
コンパイル時間 1,669 ms
コンパイル使用メモリ 24,048 KB
実行使用メモリ 9,960 KB
最終ジャッジ日時 2023-09-26 15:04:47
合計ジャッジ時間 8,834 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,656 KB
testcase_01 AC 4 ms
5,744 KB
testcase_02 AC 1,466 ms
5,660 KB
testcase_03 AC 4 ms
5,624 KB
testcase_04 AC 3 ms
5,656 KB
testcase_05 AC 4 ms
5,764 KB
testcase_06 AC 3 ms
5,656 KB
testcase_07 AC 4 ms
5,692 KB
testcase_08 AC 4 ms
5,652 KB
testcase_09 AC 3 ms
5,588 KB
testcase_10 AC 4 ms
5,692 KB
testcase_11 WA -
testcase_12 AC 4 ms
5,660 KB
testcase_13 AC 4 ms
5,660 KB
testcase_14 AC 3 ms
5,704 KB
testcase_15 AC 3 ms
5,616 KB
testcase_16 AC 3 ms
5,652 KB
testcase_17 AC 3 ms
5,632 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:39:5: warning: implicit declaration of function ‘memset’ [-Wimplicit-function-declaration]
     memset(memo, -1, sizeof(memo));
     ^~~~~~
main.c:39:5: warning: incompatible implicit declaration of built-in function ‘memset’
main.c:39:5: note: include ‘<string.h>’ or provide a declaration of ‘memset’
main.c:2:1:
+#include <string.h>
 
main.c:39:5:
     memset(memo, -1, sizeof(memo));
     ^~~~~~

ソースコード

diff #

#include<stdio.h>

#define N 100
#define W 10001

int memo[N][W], w[N], wn;

int f(int i, int j)
{
    int k;
    
    if(j == 0){
        return(j);
    }
    if(wn <= i){
        return(j);
    }
    
    if(0 < memo[i][j]){
        return(memo[i][j]);
    }else{
        for(k = i; k < wn; k++){
            if(w[k] <= j){
                memo[i][j] = f(i + 1, j - w[k]);
                if(memo[i][j] == 0){
                    break;
                }
            }
        }
    }
    return(memo[i][j]);
}


int main(int argc, const char * argv[])
{
    int i, sum = 0;
    
    memset(memo, -1, sizeof(memo));
    scanf("%d", &wn);
    for(i = 0; i < wn; i++){
        scanf("%d", &w[i]);
        sum += w[i];
    }
    if(sum % 2 == 1){
        printf("impossible\n");
    }else if(f(0, sum/2) == 0){
        printf("possible\n");
    }else{
        printf("impossible\n");
    }
    return 0;
}
0