結果
| 問題 |
No.3329 Only the Rightest Choice is Right!!!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-09 17:21:26 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 40 ms / 1,571 ms |
| コード長 | 1,251 bytes |
| コンパイル時間 | 2,790 ms |
| コンパイル使用メモリ | 281,408 KB |
| 実行使用メモリ | 38,400 KB |
| 最終ジャッジ日時 | 2025-11-02 16:31:19 |
| 合計ジャッジ時間 | 6,163 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 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_FAST32_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;
}