|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
#include <bitset>
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <set>
|
|
|
|
@ -7,8 +8,7 @@ constexpr long Y = 2000000;
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
std::set<int> xs;
|
|
|
|
|
std::set<int> bs;
|
|
|
|
|
std::bitset<8000000> xs;
|
|
|
|
|
long px, py, bx, by;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
@ -17,33 +17,24 @@ int main()
|
|
|
|
|
if (std::cin.eof())
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
auto a = sscanf(line.c_str(),
|
|
|
|
|
sscanf(line.c_str(),
|
|
|
|
|
"Sensor at x=%ld, y=%ld: closest beacon is at x=%ld, y=%ld",
|
|
|
|
|
&px, &py, &bx, &by);
|
|
|
|
|
|
|
|
|
|
std::cout << px << ' ' << py << ' ' << bx << ' ' << by;
|
|
|
|
|
long dist = std::abs(px - bx) + std::abs(py - by);
|
|
|
|
|
|
|
|
|
|
if (by == Y)
|
|
|
|
|
bs.insert(bx);
|
|
|
|
|
|
|
|
|
|
long ic = std::abs(px - bx) + std::abs(py - by);
|
|
|
|
|
|
|
|
|
|
if (Y < py - ic || Y > py + ic)
|
|
|
|
|
if (Y < py - dist || Y > py + dist)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
long spr = (ic - std::abs(py - Y));
|
|
|
|
|
px += 1000000;
|
|
|
|
|
long spr = dist - std::abs(py - Y);
|
|
|
|
|
for (long j = 0; j <= spr; ++j) {
|
|
|
|
|
xs.insert(px + j);
|
|
|
|
|
xs.insert(px - j);
|
|
|
|
|
xs.set(px + j);
|
|
|
|
|
xs.set(px - j);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::cout << " -> " << xs.size() << std::endl;
|
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
|
|
for (auto& b : bs)
|
|
|
|
|
xs.erase(b);
|
|
|
|
|
|
|
|
|
|
std::cout << "Part 1: " << xs.size() << std::endl;
|
|
|
|
|
std::cout << "Part 1: " << xs.count() - 1 << std::endl;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|