結果

問題 No.3329 Only the Rightest Choice is Right!!!
コンテスト
ユーザー elphe
提出日時 2025-08-07 00:58:44
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,566 bytes
コンパイル時間 3,846 ms
コンパイル使用メモリ 284,320 KB
実行使用メモリ 817,920 KB
最終ジャッジ日時 2025-09-09 17:07:56
合計ジャッジ時間 7,846 ms
ジャッジサーバーID
(参考情報)
judge2 / judge
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other MLE * 1 -- * 73
権限があれば一括ダウンロードができます

ソースコード

diff #

#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::vector<std::vector<std::pair<uint_fast64_t, std::vector<uint_fast32_t>>>> dp(N + 1, std::vector<std::pair<uint_fast64_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][j] = dp[i][j];
		for (uint_fast32_t j = w[i]; j <= W; ++j)
		{
			if (dp[i][j].first > dp[i][j - w[i]].first + v[i])
				dp[i + 1][j] = dp[i][j];
			else if (dp[i][j].first < dp[i][j - w[i]].first + v[i])
				dp[i + 1][j] = dp[i][j - w[i]], dp[i + 1][j].first += v[i], dp[i + 1][j].second.push_back(i + 1);
			else if (dp[i][j].second > dp[i][j - w[i]].second)
				dp[i + 1][j] = dp[i][j];
			else
				dp[i + 1][j] = dp[i][j - w[i]], dp[i + 1][j].first += v[i], dp[i + 1][j].second.push_back(i + 1);
		}
	}

	return dp[N][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;
}
0