diff options
Diffstat (limited to '')
| -rw-r--r-- | 2024/25/day25a.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/2024/25/day25a.cpp b/2024/25/day25a.cpp new file mode 100644 index 0000000..22d8c15 --- /dev/null +++ b/2024/25/day25a.cpp | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | #include <algorithm> | ||
| 2 | #include <cstdint> | ||
| 3 | #include <iostream> | ||
| 4 | #include <map> | ||
| 5 | #include <queue> | ||
| 6 | #include <ranges> | ||
| 7 | #include <set> | ||
| 8 | #include <sstream> | ||
| 9 | #include <string> | ||
| 10 | #include <string_view> | ||
| 11 | #include <vector> | ||
| 12 | using namespace std; | ||
| 13 | |||
| 14 | class KeyLock { | ||
| 15 | public: | ||
| 16 | KeyLock() { fill(a, a+5, 0); } | ||
| 17 | |||
| 18 | void addrow(const string& s) { | ||
| 19 | for (int i = 0; i < 5; i++) | ||
| 20 | a[i] += s[i] == '#'; | ||
| 21 | } | ||
| 22 | |||
| 23 | bool operator&(const KeyLock& other) const { | ||
| 24 | for (int i = 0; i < 5; i++) | ||
| 25 | if (a[i] + other.a[i] > 5) | ||
| 26 | return false; | ||
| 27 | return true; | ||
| 28 | } | ||
| 29 | private: | ||
| 30 | int a[5]; | ||
| 31 | }; | ||
| 32 | |||
| 33 | int main() { | ||
| 34 | vector<KeyLock> keys, locks; | ||
| 35 | string line; | ||
| 36 | while (getline(cin, line)) { | ||
| 37 | KeyLock k; | ||
| 38 | bool key = line[0] == '.'; | ||
| 39 | for (int i = 0; i < 5; i++) { | ||
| 40 | getline(cin, line); | ||
| 41 | k.addrow(line); | ||
| 42 | } | ||
| 43 | if (key) keys.push_back(k); | ||
| 44 | else locks.push_back(k); | ||
| 45 | getline(cin, line); | ||
| 46 | getline(cin, line); | ||
| 47 | } | ||
| 48 | |||
| 49 | int tot = 0; | ||
| 50 | for (auto k : keys) | ||
| 51 | for (auto l : locks) | ||
| 52 | tot += (k & l) ? 1 : 0; | ||
| 53 | cout << tot << endl; | ||
| 54 | return 0; | ||
| 55 | } | ||
