aboutsummaryrefslogtreecommitdiff
path: root/src/2022/day16/aoc.cpp
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2023-01-11 16:03:32 +0800
committerkaiwu <kaiwu2004@gmail.com>2023-01-11 16:03:32 +0800
commit4f950cb20871a91f75b1157413cfecb7b0ed7d66 (patch)
treef1501f256c2b3ac29a05cb69a1bb2e78683dfc96 /src/2022/day16/aoc.cpp
parentc8930c1a75a3be5fe77d0f40e8246bb9ed4007bb (diff)
downloadadvent-of-code-4f950cb20871a91f75b1157413cfecb7b0ed7d66.tar.gz
advent-of-code-4f950cb20871a91f75b1157413cfecb7b0ed7d66.zip
2022 day16 part2
Diffstat (limited to 'src/2022/day16/aoc.cpp')
-rw-r--r--src/2022/day16/aoc.cpp23
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;