結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2015-09-14 21:37:06 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 740 bytes |
コンパイル時間 | 619 ms |
コンパイル使用メモリ | 58,872 KB |
実行使用メモリ | 8,576 KB |
最終ジャッジ日時 | 2024-07-19 06:29:17 |
合計ジャッジ時間 | 7,229 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 TLE * 1 -- * 4 |
ソースコード
#include <iostream> #include <algorithm> using namespace std; int p; int w[101]; int ww[101]; int n; bool dfs(int cur,int weight){ if(weight==p) return true; if(cur==n) return false; if(weight>p) return false; if(dfs(cur+1,weight+w[cur])) return true; if(dfs(cur+1,weight)) return true; return false; } int main(){ cin>>n; for(int i=0;i<n;i++) cin >> ww[i]; int sum=0; for(int i=0;i<n;i++) sum+=ww[i]; if(sum%2){ cout << "impossible" << endl; return 0; } sort(ww,ww+n); for(int i=n-1;i>=0;i--){ w[i] = ww[n-i-1]; } p=sum/2; if(dfs(0,0)){ cout << "possible" << endl; }else{ cout << "impossible" << endl; } return 0; }