結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
roaiziro
|
| 提出日時 | 2015-09-25 15:59:43 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 905 bytes |
| コンパイル時間 | 119 ms |
| コンパイル使用メモリ | 20,608 KB |
| 実行使用メモリ | 12,320 KB |
| 最終ジャッジ日時 | 2024-07-19 09:13:19 |
| 合計ジャッジ時間 | 8,100 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 WA * 1 TLE * 1 -- * 4 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:39:5: warning: implicit declaration of function ‘memset’ [-Wimplicit-function-declaration]
39 | memset(memo, -1, sizeof(memo));
| ^~~~~~
main.c:2:1: note: include ‘<string.h>’ or provide a declaration of ‘memset’
1 | #include<stdio.h>
+++ |+#include <string.h>
2 |
main.c:39:5: warning: incompatible implicit declaration of built-in function ‘memset’ [-Wbuiltin-declaration-mismatch]
39 | memset(memo, -1, sizeof(memo));
| ^~~~~~
main.c:39:5: note: include ‘<string.h>’ or provide a declaration of ‘memset’
main.c:40:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
40 | scanf("%d", &wn);
| ^~~~~~~~~~~~~~~~
main.c:42:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
42 | scanf("%d", &w[i]);
| ^~~~~~~~~~~~~~~~~~
ソースコード
#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;
}
roaiziro