結果
問題 | No.4 おもりと天秤 |
ユーザー |
![]() |
提出日時 | 2016-07-08 14:27:06 |
言語 | C90 (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 19 ms / 5,000 ms |
コード長 | 763 bytes |
コンパイル時間 | 328 ms |
コンパイル使用メモリ | 22,272 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-26 09:36:25 |
合計ジャッジ時間 | 1,053 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:10:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | scanf("%d", &n); | ^~~~~~~~~~~~~~~ main.c:12:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | scanf("%d", &w[i]); | ^~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> int main(void) { int i, j, k; int n, w[101]; int total = 0; int memo[10001] = {0}; int memo2[10001] = {0}; scanf("%d", &n); for(i = 0;i < n;i++){ scanf("%d", &w[i]); total += w[i]; } if(total % 2 == 1){ printf("impossible\n"); return 0; } for(j = 0;j < n;j++){ for(i = 0;i < total;i++){ if(memo[i] == 1){ for(k = i + w[j];k <= total;k += w[j]){ if(memo[k] == 0){ memo2[k] = 1; break; } } } } for(i = w[j];i <= total;i += w[j]){ if(memo[i] == 0){ memo2[i] = 1; break; } } for(i = 0;i < total;i++){ memo[i] = memo[i] | memo2[i]; } } if(memo[total / 2] == 1){ printf("possible\n"); } else{ printf("impossible\n"); } return 0; }