結果
| 問題 |
No.3322 引っ張りだこ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-15 18:50:22 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,175 bytes |
| コンパイル時間 | 3,025 ms |
| コンパイル使用メモリ | 281,020 KB |
| 実行使用メモリ | 9,516 KB |
| 最終ジャッジ日時 | 2025-10-31 20:30:34 |
| 合計ジャッジ時間 | 5,961 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 WA * 42 |
ソースコード
#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::array<std::vector<std::array<uint_least64_t, 2>>, 2> dp = { std::vector<std::array<uint_least64_t, 2>>(K + 1, { 0, 0 }), std::vector<std::array<uint_least64_t, 2>>(K + 1, { 0, 0 }) };
dp[1][0] = { A[0], 0 };
for (uint_fast32_t j = 1; j <= K; ++j)
dp[1][j] = { A[0], B[0] };
for (uint_fast32_t i = 1; i < N; ++i)
{
dp[(i & 1) ^ 1][0] = { dp[i & 1][0][0] + A[i], 0 };
for (uint_fast32_t j = 1; j <= K; ++j)
dp[(i & 1) ^ 1][j] = { std::max<uint_fast64_t>(dp[i & 1][j][0], dp[i & 1][j - 1][1]) + A[i], std::max<uint_fast64_t>(dp[i & 1][j - 1][0], dp[i & 1][j][1]) + B[i] };
}
return std::max<uint_fast64_t>(dp[N & 1][K][0], dp[N & 1][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;
}