blob: fb537532e89ce9f85125067db3462321b72a038d (
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#include <cstdio>
#include <iostream>
#include <set>
#include <string>
constexpr long Y = 2000000;
int main()
{
std::set<int> xs;
std::set<int> bs;
long px, py, bx, by;
do {
std::string line;
std::getline(std::cin, line);
if (std::cin.eof())
break;
auto a = 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;
if (by == Y)
bs.insert(bx);
long ic = std::abs(px - bx) + std::abs(py - by);
if (Y < py - ic || Y > py + ic)
continue;
long spr = (ic - std::abs(py - Y));
for (long j = 0; j <= spr; ++j) {
xs.insert(px + j);
xs.insert(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;
return 0;
}
|