結果
問題 |
No.4 おもりと天秤
|
ユーザー |
|
提出日時 | 2024-09-27 17:38:11 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 673 bytes |
コンパイル時間 | 3,175 ms |
コンパイル使用メモリ | 247,224 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-27 17:38:15 |
合計ジャッジ時間 | 3,609 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <bits/stdc++.h> using i64 = long long; int main() { std::cin.tie(nullptr)->sync_with_stdio(false); int n; std::cin >> n; std::vector<i64> a(n); for (auto &x : a) std::cin >> x; auto s = std::accumulate(a.begin(), a.end(), 0LL); if (s & 1) { std::cout << "impossible\n"; return 0; } s >>= 1; std::vector<i64> dp(s + 1); dp[0] = 1; for (int i = 0; i < n; ++i) { for (int j = s; j >= 0; --j) { if (j - a[i] >= 0 && dp[j - a[i]]) { dp[j] = 1; } } } std::cout << (dp[s] ? "possible" : "impossible") << '\n'; return 0; }