結果
| 問題 | No.4 おもりと天秤 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-15 15:59:53 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 2 ms / 5,000 ms |
| + 416µs | |
| コード長 | 661 bytes |
| 記録 | |
| コンパイル時間 | 2,770 ms |
| コンパイル使用メモリ | 178,376 KB |
| 実行使用メモリ | 9,868 KB |
| 最終ジャッジ日時 | 2026-10-15 15:59:58 |
| 合計ジャッジ時間 | 4,552 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <iostream>
#include <vector>
int main() {
using namespace std;
int n, tot = 0;
cin >> n;
vector<int> w(n);
for (auto &e : w) {
cin >> e;
tot += e;
}
if (tot % 2 > 0) {
cout << "impossible\n";
return 0;
}
const int m = tot / 2;
vector dp(n + 1, vector<bool>(m + 1, false));
dp[0][0] = true;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= m; j++) {
if (!dp[i][j]) { continue; }
dp[i + 1][j] = true;
if (j + w[i] <= m) { dp[i + 1][j + w[i]] = true; }
}
}
cout << (dp[n][m] ? "possible\n" : "impossible\n");
}