#include "common/aoc.h" namespace y2016::day20 { using Input = std::vector>; REGISTER_DAY(2016, Day20, Input, uint32_t); REGISTER_TEST_EXAMPLE(2016, Day20, ExampleInput, 1, 3); REGISTER_TEST(2016, Day20, Input, 1, 19449262); REGISTER_TEST_EXAMPLE(2016, Day20, ExampleInput, 2, 2); REGISTER_TEST(2016, Day20, Input, 2, 119); READ_INPUT(input) { std::vector> vec; std::string str; while (getline(input, str)) { std::pair pair; std::stringstream ss{str}; ss >> pair.first >> "-" >> pair.second; vec.emplace_back(pair); } std::sort(vec.begin(), vec.end()); return vec; } OUTPUT1(input) { if (input.front().first != 0) return 0; for (int i = 0; i < input.size(); i++) { if (input[i].second + 1 < input[i + 1].first) return input[i].second + 1; } return 0; } OUTPUT2(input) { uint64_t allowed = input.front().first; uint64_t currentMax = input.front().second; for (int i = 1; i < input.size(); i++) { if (currentMax < input[i].first - 1) { allowed += input[i].first - currentMax - 1; currentMax = input[i].second; } else { currentMax = std::max(currentMax, input[i].second); } } uint32_t max = isExample ? 9 : std::numeric_limits::max(); allowed += max - currentMax; return allowed; } }