結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
yj1145141919
|
| 提出日時 | 2016-09-13 14:52:38 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 837 bytes |
| コンパイル時間 | 140 ms |
| コンパイル使用メモリ | 24,012 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-17 04:48:39 |
| 合計ジャッジ時間 | 919 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 9 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:24:9: warning: ignoring return value of ‘fgets’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
24 | fgets(str, sizeof(str), stdin);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:27:9: warning: ignoring return value of ‘fgets’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
27 | fgets(str, sizeof(str), stdin);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
/*
* douteki.c
*
* Created on: 2016/09/13
* Author: admin
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(){
char str[10000];
char *tmp;
int n=0, i=0, j=0;
int sum_w=0, half=0;
int w[100] = {0};
int check[10001] = {0};
check[0] = 1;
fgets(str, sizeof(str), stdin);
n = atoi(str);
fgets(str, sizeof(str), stdin);
tmp = strtok(str, " ");
w[0] = atoi(tmp);
sum_w = w[0];
for(i = 1; i < n; i++){
tmp = strtok(NULL, " ");
w[i] = atoi(tmp);
sum_w += w[i];
}
half = sum_w / 2;
if(half % 2 == 1){
printf("impossible\n");
goto end;
}
for(i = 0; i < n; i++){
for(j = sum_w; j >= 0; j--){
if(check[j] == 1){
check[w[i] + j] = 1;
}
}
}
if(check[half] == 1){
printf("possible\n");
}
else{
printf("impossible\n");
}
end:
return 0;
}
yj1145141919