day13a.cpp (1351B)
1 /* 2 This is the dumb solution I wrote before actually thinking how to solve 3 the problem. Check out day13b.cpp for a better solution (just remove the 4 +N in the input-reading part). 5 6 Also, both this file and day13b.cpp take a different input format than 7 what was given. I used clean.sh to convert from 'input-original' to 'input'. 8 */ 9 10 #include <algorithm> 11 #include <iostream> 12 #include <map> 13 #include <ranges> 14 #include <set> 15 #include <sstream> 16 #include <string> 17 #include <string_view> 18 #include <vector> 19 using namespace std; 20 21 #define INF 999999 22 23 class Machine { 24 public: 25 pair<int, int> a, b, prize; 26 27 Machine(int a1, int a2, int b1, int b2, int p1, int p2) : 28 a(a1, a2), b(b1, b2), prize(p1, p2) {} 29 }; 30 31 int main() { 32 string line; 33 int a1, a2, b1, b2, p1, p2; 34 vector <Machine> machines; 35 while (cin >> a1 >> a2) { 36 cin >> b1 >> b2; 37 cin >> p1 >> p2; 38 getline(cin, line); 39 machines.push_back(Machine(a1, a2, b1, b2, p1, p2)); 40 } 41 42 int tot = 0; 43 for (auto m : machines) { 44 int minp = INF; 45 for (int i = 0; i <= 100; i++) { 46 int x = m.prize.first-m.a.first*i; 47 int y = m.prize.second-m.a.second*i; 48 if (x % m.b.first != 0 || y % m.b.second != 0) 49 continue; 50 int a = x / m.b.first; 51 int b = y / m.b.second; 52 if (a != b) 53 continue; 54 minp = min(minp, 3*i+a); 55 } 56 tot += minp == INF ? 0 : minp; 57 } 58 59 cout << tot << endl; 60 61 return 0; 62 }