diff options
author | kaiwu <kaiwu2004@gmail.com> | 2023-01-17 17:23:01 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2023-01-17 17:23:01 +0800 |
commit | 2bfaa055be9983352bf11212169d31aa8fbb525e (patch) | |
tree | a0c0319f9cc546332732210bdab0f83ea4391a39 | |
parent | b8022c023c75b4a8df80b883fe5f7ec3284c2ba1 (diff) | |
download | advent-of-code-2bfaa055be9983352bf11212169d31aa8fbb525e.tar.gz advent-of-code-2bfaa055be9983352bf11212169d31aa8fbb525e.zip |
2022 day19 part2 no cache
-rw-r--r-- | src/2022/day19/aoc.cpp | 32 |
1 files changed, 4 insertions, 28 deletions
diff --git a/src/2022/day19/aoc.cpp b/src/2022/day19/aoc.cpp index f3e0ee3..737c230 100644 --- a/src/2022/day19/aoc.cpp +++ b/src/2022/day19/aoc.cpp @@ -18,18 +18,7 @@ struct build_result { bool b5 = r1.robots[1] < r2.robots[1]; bool b6 = r1.robots[1] > r2.robots[1]; bool b7 = r1.robots[0] < r2.robots[0]; - // bool b8 = r1.robots[0] > r2.robots[0]; - - // bool c1 = r1.products[3] < r2.products[3]; - // bool c2 = r1.products[3] > r2.products[3]; - // bool c3 = r1.products[2] < r2.products[2]; - // bool c4 = r1.products[2] > r2.products[2]; - // bool c5 = r1.products[1] < r2.products[1]; - // bool c6 = r1.products[1] > r2.products[1]; - // bool c7 = r1.products[0] < r2.products[0]; - - // bool x2 = c1 ? true : c2 ? false : c3 ? true : c4 ? false : c5 ? true : c6 ? false : c7; - return b1 ? true : b2 ? false : b3 ? true : b4 ? false : b5 ? true : b6 ? false : b7; // ? true : b8 ? false : x2; + return b1 ? true : b2 ? false : b3 ? true : b4 ? false : b5 ? true : b6 ? false : b7; } }; @@ -142,24 +131,16 @@ struct build_cache { } }; -void build(int m, std::vector<build_cache>& cache, const blueprint& b, build_result r, build_result& max, int* mx) { +void build(int m, const blueprint& b, build_result r, build_result& max) { // print_result(b.idx, total - m, r); if (m > 0) { - auto& c = cache[total - m]; - // auto cm = c.get(r); - // if (cm != INT32_MIN && r.products[3] <= cm) { - // return; - // } - std::vector<build_result> rs; build_product(b, r, rs); for (auto& r0 : rs) { - build(m - 1, cache, b, r0, max, mx); - c.set(r0, *mx); + build(m - 1, b, r0, max); } } else { - *mx = max.products[3]; if (less(max, r)) { max = r; } @@ -174,16 +155,11 @@ std::pair<int, int> day19(line_view file) { }); std::vector<build_result> rs; - std::vector<build_cache> cs{total}; for (auto& b : bs) { build_result r; build_result m; // b.print(); - for (int i = 0; i < total; i++) { - cs[i].cache.clear(); - } - int x{INT32_MIN}; - build(total, cs, b, r, m, &x); + build(total, b, r, m); print_result(b.idx, total, m); rs.push_back(m); } |