結果
問題 | No.4 おもりと天秤 |
ユーザー |
![]() |
提出日時 | 2019-08-02 21:25:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 575 bytes |
コンパイル時間 | 746 ms |
コンパイル使用メモリ | 72,448 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 08:17:19 |
合計ジャッジ時間 | 1,207 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <algorithm> #include <iostream> #include <vector> #include <numeric> using namespace std; int main() { const int MAX = 100 * 100; int n; cin >> n; vector<int> w(n); for (int &wi: w) cin >> wi; vector<int> dp(MAX + 1, 0); dp[0] = 1; for (int wi: w) { for (int i = MAX - wi; i >= 0; i--) dp[i + wi] |= dp[i]; } int sum = accumulate(w.begin(), w.end(), 0); if (sum % 2 == 0) { cout << (dp[sum / 2] ? "possible" : "impossible") << endl; } else { cout << "impossible" << endl; } return 0; }