diff --git a/2023/04.cpp b/2023/04.cpp index 0855b5e..6c6bf35 100644 --- a/2023/04.cpp +++ b/2023/04.cpp @@ -72,11 +72,10 @@ auto Part1(std::vector const& wins) -> std::uint64_t auto Part2(std::vector const& wins) -> std::size_t { - std::vector psums(wins); - psums.push_back(0); + std::vector psums(wins.size() + 1); for (std::size_t i = wins.size(); i --> 0;) { - psums[i] = 1 + 2 * psums[i+1] - psums[1 + i + psums[i]]; + psums[i] = 1 + 2 * psums[i + 1] - psums[i + 1 + wins[i]]; } return psums.front(); }