From 3d665e5ebb5fcf91b60f6587c5e1006c842db320 Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Thu, 10 Nov 2022 21:25:27 -0800 Subject: [PATCH] Update 20.cpp --- 2019/20.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/2019/20.cpp b/2019/20.cpp index 95525cc..638f298 100644 --- a/2019/20.cpp +++ b/2019/20.cpp @@ -118,11 +118,11 @@ auto FindDistances(Map const& map, Portals const& portals) { Distances distances; std::map names; - for (auto [k,v] : portals) { + for (auto const& [k,v] : portals) { names[v] = k; } - for (auto const [start_name, start_coord] : portals) { + for (auto const& [start_name, start_coord] : portals) { distances[start_name] = FindDistancesFrom(map, names, distances, start_name, start_coord); } @@ -132,11 +132,11 @@ auto FindDistances(Map const& map, Portals const& portals) { auto SolveMaze(Distances const& distances, bool const recursive) -> std::int64_t { // Track current positions and current set of keys in easy to compare form - using Visited = std::pair; + using Visited = std::pair; std::set seen; // Priority queue returning lowest path cost states first. - using PqElt = std::tuple; + using PqElt = std::tuple; using PqCmp = decltype([](PqElt const& x, PqElt const& y) { return std::get<0>(x) > std::get<0>(y); }); std::priority_queue, PqCmp> todo; @@ -144,7 +144,7 @@ auto SolveMaze(Distances const& distances, bool const recursive) -> std::int64_t todo.emplace(0, 0, "-AA"); while(!todo.empty()) { - auto [steps, depth, name] = todo.top(); + auto const [steps, depth, name] = todo.top(); todo.pop(); if (name == "-ZZ") { return steps; } if (seen.emplace(depth, name).second) {