diff --git a/2024/13/main-1.cpp b/2024/13/main-1.cpp new file mode 100644 index 0000000..155605b --- /dev/null +++ b/2024/13/main-1.cpp @@ -0,0 +1,45 @@ +#include +using namespace std; + +typedef unsigned long long ull; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int total = 0; + + while (!cin.eof()) { + int ax, ay, bx, by, px, py; + cin.ignore(12); + cin >> ax; + cin.ignore(4); + cin >> ay; + cin.ignore(13); + cin >> bx; + cin.ignore(4); + cin >> by; + cin.ignore(10); + cin >> px; + cin.ignore(4); + cin >> py; + cin.ignore(2); + + int smallest = -1; + for (int a = 0; a <= 100; a++) { + for (int b = 0; b <= 100; b++) { + if (ax * a + bx * b == px && ay * a + by * b == py) { + int n = a * 3 + b; + if (smallest == -1 || n < smallest) { + smallest = n; + } + } + } + } + if (smallest != -1) { + total += smallest; + } + } + + cout << total << '\n'; +} diff --git a/2024/13/main-2.cpp b/2024/13/main-2.cpp new file mode 100644 index 0000000..90c4864 --- /dev/null +++ b/2024/13/main-2.cpp @@ -0,0 +1,43 @@ +#include +using namespace std; + +typedef long long ll; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + ll total = 0; + + while (!cin.eof()) { + int ax, ay, bx, by; + ll px, py; + cin.ignore(12); + cin >> ax; + cin.ignore(4); + cin >> ay; + cin.ignore(13); + cin >> bx; + cin.ignore(4); + cin >> by; + cin.ignore(10); + cin >> px; + cin.ignore(4); + cin >> py; + cin.ignore(2); + + px += 10000000000000; + py += 10000000000000; + + ll bd = bx * ay - by * ax; + ll pd = px * ay - py * ax; + if (pd % bd != 0) { + continue; + } + ll b = pd / bd; + ll a = (px - bx * b) / ax; + total += a * 3 + b; + } + + cout << total << '\n'; +}