結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
not_522
|
| 提出日時 | 2015-07-16 18:40:01 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 773 bytes |
| コンパイル時間 | 1,372 ms |
| コンパイル使用メモリ | 160,476 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-26 09:14:45 |
| 合計ジャッジ時間 | 2,228 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template<typename Weight, typename Value, typename Function> Value knapsack(Weight maxWeight, const vector<Weight>& weight, const vector<Value>& value, Value init = 0, Function func = plus<Weight>()) {
vector<Value> dp(maxWeight + 1, 0);
dp[0] = init;
for (size_t i = 0; i < weight.size(); ++i) {
for (auto w = maxWeight; w >= weight[i]; --w) {
dp[w] = max(dp[w], func(dp[w - weight[i]], value[i]));
}
}
return dp[maxWeight];
}
int main() {
int n;
cin >> n;
vector<int> w(n);
for (int& i : w) cin >> i;
static const int sum = accumulate(w.begin(), w.end(), 0);
cout << (sum % 2 == 0 && knapsack(sum / 2, w, vector<int>(n, 1), 1, multiplies<int>()) ? "possible" : "impossible") << endl;
}
not_522