結果

問題 No.3322 引っ張りだこ
コンテスト
ユーザー elphe
提出日時 2025-09-15 18:58:40
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 967 bytes
コンパイル時間 3,602 ms
コンパイル使用メモリ 278,656 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-10-31 20:30:38
合計ジャッジ時間 6,369 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1 WA * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

// O(NK) 解法
[[nodiscard]] static inline constexpr uint_fast64_t solve(const uint_fast32_t N, const uint_fast32_t K, const std::vector<uint_least32_t>& A, const std::vector<uint_least32_t>& B) noexcept
{
	std::vector<std::array<uint_least64_t, 2>> dp(K + 1, { 0, 0 });
	for (uint_fast32_t j = K; j > 0; --j)
		dp[j] = { A[0], B[0] };
	dp[0] = { A[0], 0 };

	for (uint_fast32_t i = 1; i < N; ++i)
	{
		for (uint_fast32_t j = K; j > 0; --j)
			dp[j] = { std::max<uint_fast64_t>(dp[j][0], dp[j - 1][1]) + A[i], std::max<uint_fast64_t>(dp[j - 1][0], dp[j][1]) + B[i] };
		dp[0] = { dp[0][0] + A[i], 0 };
	}

	return std::max<uint_fast64_t>(dp[K][0], dp[K][1]);
}

int main()
{
	std::cin.tie(nullptr);
	std::ios::sync_with_stdio(false);

	uint_fast32_t N, K;
	std::cin >> N >> K;
	std::vector<uint_least32_t> A(N), B(N);
	for (auto& a : A) std::cin >> a;
	for (auto& b : B) std::cin >> b;

	std::cout << solve(N, K, A, B) << '\n';
	return 0;
}
0