This commit is contained in:
Eric Mertens 2023-12-04 16:29:48 -08:00
parent d66b3d3561
commit 829c9aafce

View File

@ -72,11 +72,10 @@ auto Part1(std::vector<std::size_t> const& wins) -> std::uint64_t
auto Part2(std::vector<std::size_t> const& wins) -> std::size_t auto Part2(std::vector<std::size_t> const& wins) -> std::size_t
{ {
std::vector<std::size_t> psums(wins); std::vector<std::size_t> psums(wins.size() + 1);
psums.push_back(0);
for (std::size_t i = wins.size(); i --> 0;) 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(); return psums.front();
} }