結果
問題 | No.4 おもりと天秤 |
ユーザー | roaiziro |
提出日時 | 2015-09-25 17:06:10 |
言語 | C90 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 885 bytes |
コンパイル時間 | 183 ms |
コンパイル使用メモリ | 24,200 KB |
実行使用メモリ | 5,840 KB |
最終ジャッジ日時 | 2023-09-26 15:05:37 |
合計ジャッジ時間 | 1,418 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
コンパイルメッセージ
main.c: In function ‘main’: main.c:35:5: warning: implicit declaration of function ‘memset’ [-Wimplicit-function-declaration] memset(memo, -1, sizeof(memo)); ^~~~~~ main.c:35:5: warning: incompatible implicit declaration of built-in function ‘memset’ main.c:35:5: note: include ‘<string.h>’ or provide a declaration of ‘memset’ main.c:2:1: +#include <string.h> main.c:35:5: memset(memo, -1, sizeof(memo)); ^~~~~~
ソースコード
#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 || wn <= i){ return(j); } if(0 < memo[i][j]){ return(memo[i][j]); }else{ memo[i][j] = 1; for(k = i; k < wn; k++){ if(w[k] <= j){ if(f(i + 1, j - w[k]) == 0){ return(0); } } } } 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]; } printf("sum=%d\n", sum); if(sum % 2 == 1){ printf("impossible\n"); }else if(f(0, sum/2) == 0){ printf("possible\n"); }else{ printf("impossible\n"); } return 0; }