Branch data Line data Source code
1 : : #include <iostream>
2 : : #include <fstream>
3 : : #include <vector>
4 : : #include <string>
5 : : #include <algorithm>
6 : : #include <ranges>
7 : : using namespace std;
8 : :
9 : 2 : int main() {
10 : 2 : ifstream file("input.txt");
11 [ + + ]: 2 : if (!file) {
12 : 1 : cerr << "Error opening file: input.txt" << endl;
13 : 1 : return 1;
14 : : }
15 : :
16 : 1 : vector<uint32_t> locks;
17 : 1 : vector<uint32_t> keys;
18 [ + + ]: 1000 : for (string line; getline(file, line);) {
19 [ + + ]: 999 : if (line.empty()) {
20 : 499 : continue;
21 : : }
22 : 500 : uint32_t packed = 0;
23 [ + + + - : 3500 : for (size_t row = 0; row < 6 && getline(file, line); ++row) {
+ + ]
24 [ + + ]: 18000 : for (size_t col = 0; col < 5; ++col) {
25 [ + + ]: 15000 : if (line[col] == '#') {
26 : 7534 : packed |= (1U << (row * 5 + col));
27 : : }
28 : : }
29 : : }
30 [ + + ]: 500 : (packed & (1 << 29) ? locks : keys).push_back(packed);
31 : 1 : }
32 : :
33 : 62500 : auto isValidPair = [](const auto& tup) {
34 : 62500 : auto [lock, key] = tup;
35 : 62500 : return (lock & key) == 0;
36 : : };
37 : :
38 : 1 : cout << static_cast<uint64_t>(ranges::count_if(views::cartesian_product(locks, keys), isValidPair)) << endl;
39 [ + + ]: 3 : }
|