diff --git a/2024/10/main-1.cpp b/2024/10/main-1.cpp new file mode 100644 index 0000000..ae736c0 --- /dev/null +++ b/2024/10/main-1.cpp @@ -0,0 +1,60 @@ +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + string line; + vector>>> m; + int h = 0; + while (getline(cin, line) && !line.empty()) { + istringstream l(line); + char c; + vector>> mm; + while (l >> c) { + set s; + if (c == '9') { + s.insert(h); + } + mm.push_back({c - '0', s}); + h++; + } + m.push_back(mm); + } + + int xm = m.size(), ym = m[0].size(); + + for (int i = 9; i > 0; i--) { + for (int x = 0; x < xm; x++) { + for (int y = 0; y < ym; y++) { + auto &[n, c] = m[x][y]; + if (n != i) { + continue; + } + cout << i << ' ' << x << ' ' << y << ' ' << endl; + vector> xxyy = { + {x - 1, y}, {x + 1, y}, {x, y - 1}, {x, y + 1}}; + for (auto &[xx, yy] : xxyy) { + if (xx < 0 || yy < 0 || xx >= xm || yy >= ym) { + continue; + } + auto &[nn, cc] = m[xx][yy]; + if (nn == n - 1) { + cc.insert(c.begin(), c.end()); + } + } + } + } + } + + int sum = 0; + for (auto &mm : m) { + for (auto &[n, c] : mm) { + if (n == 0) { + sum += c.size(); + } + } + } + cout << sum << '\n'; +} diff --git a/2024/10/main-2.cpp b/2024/10/main-2.cpp new file mode 100644 index 0000000..ff765f3 --- /dev/null +++ b/2024/10/main-2.cpp @@ -0,0 +1,54 @@ +#include +using namespace std; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + string line; + vector>> m; + while (getline(cin, line) && !line.empty()) { + istringstream l(line); + char c; + vector> mm; + while (l >> c) { + mm.push_back({c - '0', c == '9' ? 1 : 0}); + } + m.push_back(mm); + } + + int xm = m.size(), ym = m[0].size(); + + for (int i = 9; i > 0; i--) { + for (int x = 0; x < xm; x++) { + for (int y = 0; y < ym; y++) { + auto &[n, c] = m[x][y]; + if (n != i) { + continue; + } + cout << i << ' ' << x << ' ' << y << ' ' << endl; + vector> xxyy = { + {x - 1, y}, {x + 1, y}, {x, y - 1}, {x, y + 1}}; + for (auto &[xx, yy] : xxyy) { + if (xx < 0 || yy < 0 || xx >= xm || yy >= ym) { + continue; + } + auto &[nn, cc] = m[xx][yy]; + if (nn == n - 1) { + cc += c; + } + } + } + } + } + + int sum = 0; + for (auto &mm : m) { + for (auto &[n, c] : mm) { + if (n == 0) { + sum += c; + } + } + } + cout << sum << '\n'; +}