結果

問題 No.4 おもりと天秤
ユーザー roaiziroroaiziro
提出日時 2015-09-25 15:32:07
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 887 bytes
コンパイル時間 406 ms
コンパイル使用メモリ 19,840 KB
実行使用メモリ 13,880 KB
最終ジャッジ日時 2024-07-19 09:12:49
合計ジャッジ時間 8,341 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,504 KB
testcase_01 WA -
testcase_02 AC 1,563 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,504 KB
testcase_11 WA -
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:37:5: warning: implicit declaration of function ‘memset’ [-Wimplicit-function-declaration]
   37 |     memset(memo, -1, sizeof(memo));
      |     ^~~~~~
main.c:1:1: note: include ‘<string.h>’ or provide a declaration of ‘memset’
  +++ |+#include <string.h>
    1 | #define N 100
main.c:37:5: warning: incompatible implicit declaration of built-in function ‘memset’ [-Wbuiltin-declaration-mismatch]
   37 |     memset(memo, -1, sizeof(memo));
      |     ^~~~~~
main.c:37:5: note: include ‘<string.h>’ or provide a declaration of ‘memset’
main.c:38:5: warning: implicit declaration of function ‘scanf’ [-Wimplicit-function-declaration]
   38 |     scanf("%d", &wn);
      |     ^~~~~
main.c:1:1: note: include ‘<stdio.h>’ or provide a declaration of ‘scanf’
  +++ |+#include <stdio.h>
    1 | #define N 100
main.c:38:5: warning: incompatible implicit declaration of built-in function ‘scanf’ [-Wbuiltin-declaration-mismatch]
   38 |     scanf("%d", &wn);
      |     ^~~~~
main.c:38:5: note: include ‘<stdio.h>’ or provide a declaration of ‘scanf’
main.c:44:9: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
   44 |         printf("impossiblen\n");
      |         ^~~~~~
main.c:44:9: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
main.c:44:9: warning: incompatible implicit declaration of built-in function ‘printf’ [-Wbuiltin-declaration-mismatch]
main.c:44:9: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
main.c:46:9: warning: incompatible implicit declaration of built-in function ‘printf’ [-Wbuiltin-declaration-mismatch]
   46 |         printf("possible\n");
      |         ^~~~~~
main.c:46:9: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
main.c:48:9: warning: incompatible implicit declaration of built-in function ‘printf’ [-Wbuiltin-declaration-mismatch]
   48 |         p

ソースコード

diff #

#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("impossiblen\n");
    }else if(f(0, sum/2) == 0){
        printf("possible\n");
    }else{
        printf("impossible\n");
    }
    return 0;
}
0