結果
問題 | No.4 おもりと天秤 |
ユーザー |
![]() |
提出日時 | 2016-03-13 22:16:23 |
言語 | C++11 (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 782 bytes |
コンパイル時間 | 823 ms |
コンパイル使用メモリ | 75,256 KB |
実行使用メモリ | 8,704 KB |
最終ジャッジ日時 | 2024-09-25 11:28:03 |
合計ジャッジ時間 | 7,547 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 TLE * 1 -- * 4 |
ソースコード
#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],make_num; bool bfs(int now,int sum){ if(sum == make_num) return true; if(sum > make_num || now == -1) return false; return bfs(now - 1,sum + w[now]) || bfs(now - 1,sum); } int main() { bool ans = false; cin >> n; for(int i = 0;i < n;i++){ cin >> w[i]; make_num += w[i]; } sort(w,w + n); if(make_num % 2 == 1) ans = false; else{ make_num = make_num / 2; ans = bfs(n-1,0); } if(ans) cout << "possible" << endl; else cout << "impossible" << endl; return 0; }