aboutsummaryrefslogtreecommitdiff
path: root/2024
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-12-22 10:12:09 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2024-12-22 10:12:09 +0100
commit24ceca020ca7cefc5e0144f87fa3bbc5359b509d (patch)
tree3064020ebe59d859b19a40df109141268406243a /2024
parent7ec64aaf7c3e0feb3424ef696483f282fbe8f801 (diff)
downloadaoc-24ceca020ca7cefc5e0144f87fa3bbc5359b509d.tar.gz
aoc-24ceca020ca7cefc5e0144f87fa3bbc5359b509d.zip
Now day 22 part 2 is reasonably fast
Diffstat (limited to '2024')
-rw-r--r--2024/22/day22b.cpp13
1 files changed, 6 insertions, 7 deletions
diff --git a/2024/22/day22b.cpp b/2024/22/day22b.cpp
index 5e4e423..61d4767 100644
--- a/2024/22/day22b.cpp
+++ b/2024/22/day22b.cpp
@@ -28,6 +28,7 @@ int main() {
28 int64_t s; 28 int64_t s;
29 vector<vector<pair<int, int>>> spc; 29 vector<vector<pair<int, int>>> spc;
30 vector<map<int64_t, int64_t>> tt; 30 vector<map<int64_t, int64_t>> tt;
31 map<int64_t, int64_t> sums;
31 set<int64_t> seqs; 32 set<int64_t> seqs;
32 33
33 for (int i = 0; cin >> s; i++) { 34 for (int i = 0; cin >> s; i++) {
@@ -47,14 +48,12 @@ int main() {
47 } 48 }
48 } 49 }
49 50
50 int64_t best = 0; 51 for (unsigned i = 0; i < spc.size(); i++)
51 for (auto k : seqs) { 52 for (auto [k, v] : tt[i])
52 int64_t tot = 0; 53 sums[k] += v;
53 for (unsigned i = 0; i < spc.size(); i++)
54 tot += tt[i][k];
55 best = max(best, tot);
56 };
57 54
55 auto values = views::values(sums);
56 auto best = *max_element(values.begin(), values.end());
58 cout << best << endl; 57 cout << best << endl;
59 58
60 return 0; 59 return 0;

Generated with cgit - Back to sebastiano.tronto.net