結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2018-03-08 18:23:09 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 690 bytes |
コンパイル時間 | 1,333 ms |
コンパイル使用メモリ | 163,636 KB |
実行使用メモリ | 13,640 KB |
最終ジャッジ日時 | 2024-10-05 08:07:04 |
合計ジャッジ時間 | 7,914 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 TLE * 1 -- * 4 |
ソースコード
#include <bits/stdc++.h> using namespace std; int n,half; vector<int> w; bool isHalf(int m, int sum) { if (sum == half) { return true; } else if (sum > half) { return false; } else { for (int i = m + 1; i < n;i++) { if (isHalf(i, sum + w[m])) { return true; } } return false; } } int main() { cin >> n; w.resize(n); half = 0; for (int i = 0;i < n;i++) { cin >> w[i]; half += w[i]; } if (half % 2 != 0) { cout << "impossible" << endl; return 0; } half /= 2; sort(w.begin(), w.end(), greater<int>()); for (int i = 0;i < n;i++) { if (isHalf(i, 0)) { cout << "possible" << endl; return 0; } } cout << "impossible" << endl; return 0; }