aboutsummaryrefslogtreecommitdiff
path: root/2024/11/day11b.cpp
blob: 7f78e8ef6c06d5a55beae7190ed64d0e61336be6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <map>
#include <ranges>
#include <set>
#include <sstream>
#include <string>
#include <string_view>
#include <vector>
using namespace std;

map<pair<uint64_t, uint64_t>, uint64_t> t;

pair<uint64_t, uint64_t> split(uint64_t a) {
	int digits = 0;
	for (uint64_t b = a; b != 0; b /= 10)
		digits++;

	if (digits % 2 == 1)
		return make_pair(0, 0);

	uint64_t j = 1;
	for (int k = 0; k < digits/2; k++)
		j *= 10;

	return make_pair(a/j, a%j);
}

uint64_t count(uint64_t a, int n) {
	if (n == 0)
		return 1;

	if (auto it = t.find(make_pair(a, n)); it != t.end())
		return it->second;

	if (a == 0)
		return t[make_pair(a, n)] = count(1, n-1);

	if (auto [x, y] = split(a); x != 0) {
		auto c1 = count(x, n-1);
		auto c2 = count(y, n-1);
		return t[make_pair(a, n)] = c1+c2;
	}

	return t[make_pair(a, n)] = count(a*2024, n-1);
}

int main() {
	uint64_t x;
	vector<uint64_t> old, v;
	while (cin >> x)
		v.push_back(x);

	uint64_t tot = 0;
	for (auto a : v)
		tot += count(a, 75);

	cout << tot << endl;

	return 0;
}

Generated with cgit - Back to sebastiano.tronto.net