結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2019-10-31 01:17:45 |
言語 | C (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,135 bytes |
コンパイル時間 | 374 ms |
コンパイル使用メモリ | 30,080 KB |
実行使用メモリ | 7,040 KB |
最終ジャッジ日時 | 2024-09-14 21:59:53 |
合計ジャッジ時間 | 6,732 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 5 TLE * 1 -- * 17 |
コンパイルメッセージ
main.c: In function 'main': main.c:39:9: warning: implicit declaration of function 'isPossible' [-Wimplicit-function-declaration] 39 | if (isPossible(sum/2, 0, 0) > 0) | ^~~~~~~~~~
ソースコード
#include <stdio.h> int N; int W[100]; int main() { scanf("%d", &N); for (int i=0; i<N; i++) { scanf("%d", &(W[i])); } int sum = 0; for (int i=0; i<N; i++) { sum += W[i]; } if ((sum % 2) == 1) { printf("impossible\n"); return 0; } // bubble sort int flag = 0; while (1) { flag = 0; for (int i=0; i<N-1; i++) { if (W[i] < W[i+1]) { int tmp = W[i]; W[i] = W[i+1]; W[i+1] = tmp; flag = 1; } } if (flag == 0) break; } if (isPossible(sum/2, 0, 0) > 0) printf("possible\n"); else printf("impossible\n"); } int isPossible(int target, int weight, int pos) { int curWeight = weight + W[pos]; if (target == curWeight) return 1; if (pos == N-1) return 0; if (target < curWeight) return 0; if (isPossible(target, weight, pos+1) > 0) return 1; if (isPossible(target, curWeight, pos+1) > 0) return 1; return 0; }