結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2018-03-08 18:25:19 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 709 bytes |
コンパイル時間 | 1,381 ms |
コンパイル使用メモリ | 163,564 KB |
実行使用メモリ | 10,016 KB |
最終ジャッジ日時 | 2024-10-05 08:07:27 |
合計ジャッジ時間 | 8,097 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 { int sum2 = sum + w[m]; for (int i = m + 1; i < n;i++) { if (isHalf(i, sum2)) { 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; }