diff options
author | kaiwu <kaiwu2004@gmail.com> | 2023-01-11 23:14:39 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2023-01-11 23:14:39 +0800 |
commit | ff9557454830f4508f0d475ea54ab819f61492ab (patch) | |
tree | 51af20ed885da606cf6a5bbdfa24f12301386ea9 /src/2022/day16/aoc.cpp | |
parent | 4533046d103ebdbd20b676c9488d8192141a4372 (diff) | |
download | advent-of-code-ff9557454830f4508f0d475ea54ab819f61492ab.tar.gz advent-of-code-ff9557454830f4508f0d475ea54ab819f61492ab.zip |
2022 day16 part2
Diffstat (limited to 'src/2022/day16/aoc.cpp')
-rw-r--r-- | src/2022/day16/aoc.cpp | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/src/2022/day16/aoc.cpp b/src/2022/day16/aoc.cpp index fd911db..6298483 100644 --- a/src/2022/day16/aoc.cpp +++ b/src/2022/day16/aoc.cpp @@ -121,12 +121,12 @@ std::vector<valve_m> cango(valve* v, int m, const std::map<valve*, int>& opened) return t; } -void flow(valve_m vs[2], std::map<valve_mm, int>& visited, std::map<valve*, int> opened, int os, int total, int* max) { +void flow(valve_m vs[2], std::map<valve_mm, int> visited, std::map<valve*, int> opened, int os, int total, int* max) { auto m = std::min(vs[0].m, vs[1].m); update_total(&total, opened, m); if (vs[0].m == 0 || vs[1].m == 0) { if (*max < total) { - printf("total is %d\n", total); + printf("when (%d, %d) max is %d\n", vs[0].m, vs[1].m, total); *max = total; } } else { @@ -137,10 +137,8 @@ void flow(valve_m vs[2], std::map<valve_mm, int>& visited, std::map<valve*, int> } 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; - // } + // std::cout << os << " opened when " << vs[0].m << "/" << vs[1].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; @@ -188,17 +186,15 @@ void flow(valve_m vs[2], std::map<valve_mm, int>& visited, std::map<valve*, int> if (ns0.size() > 0 && ns1.size() > 0) { for (auto& n0 : ns0) { for (auto& n1 : ns1) { - if (n0.v != n1.v) { - valve_m vx[2]; - vx[0] = vs[0]; - vx[1] = vs[1]; + valve_m vx[2]; + vx[0] = vs[0]; + vx[1] = vs[1]; - vx[0].m -= n0.m; - vx[0].v = n0.v; - vx[1].m -= n1.m; - vx[1].v = n1.v; - flow(vx, visited, opened, os, total, max); - } + vx[0].m -= n0.m; + vx[0].v = n0.v; + vx[1].m -= n1.m; + vx[1].v = n1.v; + flow(vx, visited, opened, os, total, max); } } } |