2024 day 18

This commit is contained in:
eriedaberrie 2024-12-17 21:38:52 -08:00
parent 1e5b15a387
commit 6edb409e18

58
2024/18/main.cpp Normal file
View file

@ -0,0 +1,58 @@
#include "../../include/aoc.hpp"
#include <bits/stdc++.h>
using namespace std;
unordered_map<icoord, int> m;
const int smax = 70;
void rec(icoord c, int score) {
if (!m.contains(c)) {
return;
}
int &s = m[c];
if (s != -1 && s <= score) {
return;
}
s = score;
score++;
rec(c + icoord(1, 0), score);
rec(c + icoord(-1, 0), score);
rec(c + icoord(0, 1), score);
rec(c + icoord(0, -1), score);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string line;
bool inits[smax + 1][smax + 1] = {};
int i = 0;
while (getline(cin, line) && !line.empty()) {
// NOTE: found part 2 is just binary search on this number until you
// stop getting -1 as output
if (++i > 1024) {
break;
}
istringstream l(line);
int x, y;
l >> x;
l.ignore();
l >> y;
inits[x][y] = true;
}
for (int x = 0; x <= smax; x++) {
for (int y = 0; y <= smax; y++) {
if (!inits[x][y]) {
m[{x, y}] = -1;
}
}
}
rec({0, 0}, 0);
cout << m[{smax, smax}] << '\n';
}