結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2016-09-13 15:00:55 |
言語 | C90 (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 839 bytes |
コンパイル時間 | 163 ms |
コンパイル使用メモリ | 24,288 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-26 09:59:54 |
合計ジャッジ時間 | 987 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
コンパイルメッセージ
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(sum_w % 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; }