#include "../../include/aoc.hpp" #include using namespace std; void rec(icoord c, unordered_map &m, int score) { if (!m.contains(c)) { return; } auto &s = m[c]; if (s != -1 && s <= score) { return; } s = score; for (auto dir : icoord::units()) { rec(c + dir, m, score + 1); } } int main() { ios::sync_with_stdio(0); cin.tie(0); string line; icoord p, s, e; unordered_map ms, me; while (getline(cin, line)) { for (p.y = 0; p.y < line.size(); p.y++) { switch (line[p.y]) { case '#': continue; case 'S': s = p; break; case 'E': e = p; break; } ms[p] = -1; me[p] = -1; } p.x++; } rec(s, ms, 0); rec(e, me, 0); int t = ms[e]; int count = 0; for (auto [sc, ss] : ms) { if (ss == -1) { continue; } for (auto [ec, es] : me) { if (es == -1) { continue; } auto dc = sc - ec; int l = abs(dc.x) + abs(dc.y); if (l > 20) { continue; } if (ss + es + l <= t - 100) { count++; } } } cout << count << '\n'; }