結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-09-27 17:32:20 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 673 bytes |
| コンパイル時間 | 3,363 ms |
| コンパイル使用メモリ | 247,720 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-27 17:32:25 |
| 合計ジャッジ時間 | 4,560 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 WA * 3 |
ソースコード
#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 = 0; j <= s; ++j) {
if (dp[j] && j + a[i] <= s) {
dp[j + a[i]] = 1;
}
}
}
std::cout << (dp[s] ? "possible" : "impossible") << '\n';
return 0;
}