diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/2022/day16/aoc.cpp | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/2022/day16/aoc.cpp b/src/2022/day16/aoc.cpp index 41d21ac..ee2f409 100644 --- a/src/2022/day16/aoc.cpp +++ b/src/2022/day16/aoc.cpp @@ -140,20 +140,21 @@ void flow(valve_m vs[2], std::map<valve_mm, int>& visited, std::map<valve*, int> } if (vs[0].m == 0 && vs[1].m == 0) { if (*max < total) { + printf("total is %d\n", total); *max = total; } } else { auto p = visited.insert({{vs[0], vs[1]}, total}); if (!p.second) { - return; - // if (total <= p.first->second) { - // return; - // } + if (p.first->second >= total) { + return; + } + p.first->second = total; + } + for (auto i = 0; i < 2; i++) { + std::cout << i << " at " << vs[i].v->name << " when " << vs[i].m << " minutes left, total is " << total + << std::endl; } - // for (auto i = 0; i < 2; i++) { - // std::cout << i << " at " << vs[i].v->name << " when " << vs[i].m << " minutes left, total is " << total - // << std::endl; - // } if (os >= maxopened) { vs[0].m -= vs[0].m > 0 ? 1 : 0; vs[1].m -= vs[1].m > 0 ? 1 : 0; @@ -176,15 +177,15 @@ void flow(valve_m vs[2], std::map<valve_mm, int>& visited, std::map<valve*, int> auto& ns0 = diagram[vs[0].v]; auto& ns1 = diagram[vs[1].v]; for (auto& n0 : ns0) { + auto g0 = !is_open(n0.v, opened); for (auto& n1 : ns1) { - if (n0.v != n1.v) { + auto g1 = !is_open(n1.v, opened); + if (n0.v != n1.v && (g0 || g1)) { valve_m vx[2]; vx[0] = vs[0]; vx[1] = vs[1]; - auto g0 = !is_open(n0.v, opened); auto m0 = vx[0].m > n0.m; - auto g1 = !is_open(n1.v, opened); auto m1 = vx[1].m > n1.m; if (update(vx, n0, g0, m0, n1, g1, m1)) { auto v = visited; |