結果
問題 | No.4 おもりと天秤 |
ユーザー |
![]() |
提出日時 | 2020-08-21 14:42:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 5,000 ms |
コード長 | 600 bytes |
コンパイル時間 | 2,308 ms |
コンパイル使用メモリ | 196,568 KB |
最終ジャッジ日時 | 2025-01-13 04:43:24 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int N; cin >> N; vector<int> W(N); for (auto &w : W) { cin >> w; } int tot = std::accumulate(std::cbegin(W), std::cend(W), decltype(W)::value_type()); vector dp(tot + 1, false); dp[0] = true; for (int i = 0; i < N; i++) { for (int w = tot; w > -1; w--) { if (w - W[i] >= 0) dp[w] = dp[w] | dp[w - W[i]]; } } if (tot % 2 == 0 && dp[tot / 2]) { cout << "possible" << '\n'; } else { cout << "impossible" << '\n'; } return 0; }