結果
| 問題 | No.3329 Only the Rightest Choice is Right!!! |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-09 17:19:32 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,252 bytes |
| コンパイル時間 | 3,625 ms |
| コンパイル使用メモリ | 281,324 KB |
| 実行使用メモリ | 38,528 KB |
| 最終ジャッジ日時 | 2025-09-09 17:19:53 |
| 合計ジャッジ時間 | 16,714 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | RE * 74 |
ソースコード
#include <bits/stdc++.h>
static inline constexpr std::vector<uint_least32_t> solve(const uint_fast32_t N, const uint_fast32_t W, const std::vector<uint_least32_t>& v, const std::vector<uint_least32_t>& w) noexcept
{
std::vector<std::vector<uint_least32_t>> dp(N + 1, std::vector<uint_least32_t>(W + 1, 0));
for (uint_fast32_t i = N - 1; i != UINT_LEAST32_MAX; --i)
{
for (uint_fast32_t j = 0; j != w[i]; ++j)
dp[i][j] = dp[i + 1][j];
for (uint_fast32_t j = w[i]; j <= W; ++j)
dp[i][j] = std::max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
}
std::vector<uint_least32_t> ans;
ans.reserve(N);
for (uint_fast32_t i = 0, j = W; i != N; ++i)
if (dp[i][j] != dp[i + 1][j])
ans.push_back(i + 1), j -= w[i];
return ans;
}
static inline void output(const std::vector<uint_least32_t>& ans) noexcept
{
std::cout << ans.size() << '\n' << ans[0];
for (uint_fast32_t i = 1; i != ans.size(); ++i)
std::cout << ' ' << ans[i];
std::cout << '\n';
}
int main()
{
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
uint_fast32_t N, W, i;
std::cin >> N >> W;
std::vector<uint_least32_t> v(N), w(N);
for (i = 0; i != N; ++i) std::cin >> v[i];
for (i = 0; i != N; ++i) std::cin >> w[i];
output(solve(N, W, v, w));
return 0;
}