Add solution for 2016 Day 20
This commit is contained in:
1 parent
85f5de1be2
commit
78cb890ed7
2 files changed
+40
-7
No files matched your search
@@ -0,0 +1,3 @@
|
|||||||
|
5-8
|
||||||
|
0-2
|
||||||
|
4-7
|
||||||
+37
-7
@@ -2,30 +2,60 @@
|
|||||||
|
|
||||||
namespace y2016::day20
|
namespace y2016::day20
|
||||||
{
|
{
|
||||||
REGISTER_DAY(2016, Day20, std::vector<int>, int);
|
using Input = std::vector<std::pair<uint64_t, uint64_t>>;
|
||||||
|
REGISTER_DAY(2016, Day20, Input, uint32_t);
|
||||||
|
|
||||||
REGISTER_TEST_EXAMPLE(2016, Day20, ExampleInput, 1, 0);
|
REGISTER_TEST_EXAMPLE(2016, Day20, ExampleInput, 1, 3);
|
||||||
REGISTER_TEST(2016, Day20, Input, 1, 0);
|
REGISTER_TEST(2016, Day20, Input, 1, 19449262);
|
||||||
REGISTER_TEST_EXAMPLE(2016, Day20, ExampleInput, 2, 0);
|
REGISTER_TEST_EXAMPLE(2016, Day20, ExampleInput, 2, 2);
|
||||||
REGISTER_TEST(2016, Day20, Input, 2, 0);
|
REGISTER_TEST(2016, Day20, Input, 2, 119);
|
||||||
|
|
||||||
READ_INPUT(input)
|
READ_INPUT(input)
|
||||||
{
|
{
|
||||||
std::vector<int> vec;
|
std::vector<std::pair<uint64_t, uint64_t>> vec;
|
||||||
std::string str;
|
std::string str;
|
||||||
while (getline(input, str))
|
while (getline(input, str))
|
||||||
{
|
{
|
||||||
|
std::pair<uint32_t, uint32_t> pair;
|
||||||
|
std::stringstream ss{str};
|
||||||
|
ss >> pair.first >> "-" >> pair.second;
|
||||||
|
vec.emplace_back(pair);
|
||||||
}
|
}
|
||||||
|
std::sort(vec.begin(), vec.end());
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
OUTPUT1(input)
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
OUTPUT2(input)
|
OUTPUT2(input)
|
||||||
{
|
{
|
||||||
return 0;
|
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<uint32_t>::max();
|
||||||
|
allowed += max - currentMax;
|
||||||
|
return allowed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user