結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2018-05-27 20:41:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 509 bytes |
コンパイル時間 | 1,394 ms |
コンパイル使用メモリ | 166,656 KB |
実行使用メモリ | 10,144 KB |
最終ジャッジ日時 | 2024-06-28 19:14:02 |
合計ジャッジ時間 | 7,818 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 5 TLE * 1 -- * 17 |
ソースコード
#include<bits/stdc++.h> using namespace std; int n,w[100],sum; bool dfs(int i, int weight) { if (i == n) return weight == sum / 2; if (dfs(i + 1, weight)) return true; if (dfs(i + 1, weight + w[i])) return true; return false; } void solve() { if (sum % 2 != 0) { cout << "impossible" << endl; }else { if (dfs(0, 0)) cout << "possible" << endl; else cout << "impossible" << endl; } } int main() { cin >> n; sum = 0; for (int i = 0; i < n; i++) { cin >> w[i]; sum += w[i]; } solve(); }