結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
a01sa01to
|
| 提出日時 | 2024-03-02 00:09:11 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 748 bytes |
| コンパイル時間 | 3,089 ms |
| コンパイル使用メモリ | 253,080 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-09-29 15:37:46 |
| 合計ジャッジ時間 | 4,049 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "settings/debug.cpp"
#define _GLIBCXX_DEBUG
#else
#define Debug(...) void(0)
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;
int main() {
int n;
cin >> n;
vector<int> w(n);
rep(i, n) cin >> w[i];
constexpr int m = 10000;
vector dp(n + 1, vector<bool>(m + 1, false));
dp[0][0] = true;
rep(i, n) {
rep(j, m) {
if (dp[i][j]) {
dp[i + 1][j] = true;
if (j + w[i] <= m) dp[i + 1][j + w[i]] = true;
}
}
}
int sum = accumulate(w.begin(), w.end(), 0);
bool ans = (sum % 2 == 0) && dp[n][sum / 2];
cout << (ans ? "possible" : "impossible") << endl;
return 0;
}
a01sa01to