aboutsummaryrefslogtreecommitdiff
path: root/2024/22/day22b.cpp
blob: 61d4767b83d9205599eb705e97f703bd12f54a48 (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
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <map>
#include <queue>
#include <ranges>
#include <set>
#include <sstream>
#include <string>
#include <string_view>
#include <vector>
using namespace std;

int64_t Seq(const vector<pair<int, int>>& v, int i) {
    return (v[i-3].second+9) + 19*((v[i-2].second+9) +
	   19*((v[i-1].second+9) + 19*(v[i].second+9)));
}

int64_t next(int64_t n) {
	constexpr int64_t M = 16777216;
	n = ((n*64) ^ n) % M;
	n = ((n/32) ^ n) % M;
	n = ((n*2048) ^ n) % M;
	return n;
}

int main() {
	int64_t s;
	vector<vector<pair<int, int>>> spc;
	vector<map<int64_t, int64_t>> tt;
	map<int64_t, int64_t> sums;
	set<int64_t> seqs;

	for (int i = 0; cin >> s; i++) {
		spc.push_back(vector<pair<int, int>>());
		tt.push_back(map<int64_t, int64_t>());

		for (int j = 0; j < 2000; j++) {
			int64_t t = next(s);
			spc[i].push_back({t%10, t%10 - s%10});
			s = t;
			if (j >= 3) {
				auto k = Seq(spc[i], j);
				seqs.insert(k);
				if (tt[i].count(k) == 0)
					tt[i][k] = spc[i][j].first;
			}
		}
	}

	for (unsigned i = 0; i < spc.size(); i++)
		for (auto [k, v] : tt[i])
			sums[k] += v;

	auto values = views::values(sums);
	auto best = *max_element(values.begin(), values.end());
	cout << best << endl;

	return 0;
}

Generated with cgit - Back to sebastiano.tronto.net