blob: f46da899dc1aca57b4ed1776c0b5b3a49438fc19 (
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
|
#include <algorithm>
#include <cstdint>
#include <numeric>
#include <iostream>
consteval auto countFish(unsigned int day)
{
unsigned char input[] = {
//3,4,3,1,2
#include "in"
};
uint64_t counts[9];
std::fill(counts, counts + 9, 0);
for (int i = 0; i < sizeof(input); ++i)
++counts[input[i]];
for (int i = 0; i < day; ++i) {
std::rotate(counts, counts + 1, counts + 9);
counts[6] += counts[8];
}
return std::accumulate(counts, counts + 9, 0ull);
}
int main()
{
std::cout << "80: " << countFish(80) << std::endl;
std::cout << "256: " << countFish(256) << std::endl;
return 0;
}
|