結果
| 問題 |
No.3329 Only the Rightest Choice is Right!!!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-08-07 01:59:58 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,889 bytes |
| コンパイル時間 | 3,571 ms |
| コンパイル使用メモリ | 313,176 KB |
| 実行使用メモリ | 132,588 KB |
| 最終ジャッジ日時 | 2025-09-09 17:08:46 |
| 合計ジャッジ時間 | 15,049 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | TLE * 1 -- * 73 |
ソースコード
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
static inline constexpr std::vector<uint_fast32_t> solve(const uint_fast32_t N, const uint_fast32_t W, const std::vector<uint_fast32_t>& v, const std::vector<uint_fast32_t>& w) noexcept
{
std::array<std::vector<std::pair<uint_fast32_t, std::vector<uint_fast32_t>>>, 2> dp = { std::vector<std::pair<uint_fast32_t, std::vector<uint_fast32_t>>>(W + 1, { 0, std::vector<uint_fast32_t>(0) }), std::vector<std::pair<uint_fast32_t, std::vector<uint_fast32_t>>>(W + 1, { 0, std::vector<uint_fast32_t>(0) }) };
for (uint_fast32_t i = 0; i != N; ++i)
{
for (uint_fast32_t j = 0; j != w[i]; ++j)
dp[(i & 1) ^ 1][j] = dp[i & 1][j];
for (uint_fast32_t j = w[i]; j <= W; ++j)
{
if (dp[i & 1][j].first > dp[i & 1][j - w[i]].first + v[i])
dp[(i & 1) ^ 1][j] = dp[i & 1][j];
else if (dp[i & 1][j].first < dp[i & 1][j - w[i]].first + v[i])
dp[(i & 1) ^ 1][j] = dp[i & 1][j - w[i]], dp[(i & 1) ^ 1][j].first += v[i], dp[(i & 1) ^ 1][j].second.push_back(i + 1);
else
{
std::vector<uint_fast32_t> next(dp[i & 1][j - w[i]].second);
next.push_back(i + 1);
if (dp[i & 1][j].second > next)
dp[(i & 1) ^ 1][j] = dp[i & 1][j];
else
dp[(i & 1) ^ 1][j] = { dp[i & 1][j - w[i]].first + v[i], std::move(next) };
}
}
}
return dp[N & 1][W].second;
}
static inline void output(const std::vector<uint_fast32_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_fast32_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;
}