結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2016-03-13 22:06:22 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 802 bytes |
コンパイル時間 | 586 ms |
コンパイル使用メモリ | 72,572 KB |
実行使用メモリ | 14,008 KB |
最終ジャッジ日時 | 2024-09-25 11:23:55 |
合計ジャッジ時間 | 7,215 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 5 TLE * 1 -- * 17 |
ソースコード
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define ll long long #define INF (1 << 30) #define INFLL (1LL << 60) int n,w[101],sum = 0; bool can[5010] = {}; bool bfs(int now,int num){ bool ans = 0,ans2 = 0; if(num == sum / 2) return true; if(now == n) return false; if(num > sum / 2) return false; ans = bfs(now + 1,num + w[now]); ans2 = bfs(now + 1,num); return ans || ans2; return ans; } int main() { cin >> n; for(int i = 0;i < n;i++){ cin >> w[i]; sum += w[i]; } if(sum % 2 == true)cout << "impossible" << endl; else if(bfs(0,0))cout << "possible" << endl; else cout << "impossible" << endl; return 0; }