day22b.cpp (991B)
1 #include <algorithm> 2 #include <cstdint> 3 #include <iostream> 4 #include <map> 5 #include <queue> 6 #include <ranges> 7 #include <set> 8 #include <sstream> 9 #include <string> 10 #include <string_view> 11 #include <vector> 12 using namespace std; 13 14 int64_t Seq(int64_t a, int64_t b, int64_t c, int64_t d) { 15 return (a+9) + 19*((b+9) + 19*((c+9) + 19*(d+9))); 16 } 17 18 int64_t next(int64_t n) { 19 constexpr int64_t M = 16777216; 20 n = ((n*64) ^ n) % M; 21 n = ((n/32) ^ n) % M; 22 n = ((n*2048) ^ n) % M; 23 return n; 24 } 25 26 int main() { 27 int64_t s; 28 map<int64_t, int64_t> sums; 29 30 for (int i = 0; cin >> s; i++) { 31 int64_t a, b, c, d; 32 set<int64_t> tt; 33 34 for (int j = 0; j < 2000; j++) { 35 a = b; 36 b = c; 37 c = d; 38 d = -(s%10); 39 s = next(s); 40 d += s%10; 41 if (j >= 3) { 42 auto k = Seq(a, b, c, d); 43 if (!tt.contains(k)) { 44 tt.insert(k); 45 sums[k] += s%10; 46 } 47 } 48 } 49 } 50 51 auto values = views::values(sums); 52 auto best = *max_element(values.begin(), values.end()); 53 cout << best << endl; 54 55 return 0; 56 }