#include <bits/stdc++.h> #define ll long long #define mp make_pair #define fi first #define se second #define pb push_back #define pi pair<int, int> #define vi vector<int> #define mod 1000000007 template<typename T> bool chkmin(T &a, T b){return (b < a) ? a = b, 1 : 0;} template<typename T> bool chkmax(T &a, T b){return (b > a) ? a = b, 1 : 0;} ll ksm(ll a, ll b) {if (b == 0) return 1; ll ns = ksm(a, b >> 1); ns = ns * ns % mod; if (b & 1) ns = ns * a % mod; return ns;} using namespace std; #define ar3 array<int, 3> const int maxn = 2e6 + 5; ar3 a; ar3 b; map<ar3, int> r; ar3 q[maxn]; int fr, ed; int ans[maxn]; int main() { for (int i = 0; i < maxn; i++) ans[i] = 1e9; for (int i = 0; i < 3; i++) cin >> a[i]; for (int i = 0; i < 3; i++) cin >> b[i]; q[ed++] = b; r[b] = 0; while (fr < ed) { ar3 x = q[fr++]; int cd = r[x]; for (int j = 0; j < 3; j++) chkmin(ans[x[j]], cd); for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { if (i == j) continue; int tot = x[i] + x[j]; for (int g = 0; g < 2; g++) { ar3 nx = x; nx[i] = g * a[i]; nx[j] = tot - nx[i]; if (nx[j] < 0 || nx[j] > a[j]) continue; if (!r.count(nx)) r[nx] = cd + 1, q[ed++] = nx; } } } for (int i = 0; i <= a[2]; i++) { if (ans[i] > 1e8) ans[i] = -1; printf("%d ", ans[i]); } return (0-0); // <3 cxr } /* 5 1 2 1 1 1 4 1 5 1 1*/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #include <bits/stdc++.h> #define ll long long #define mp make_pair #define fi first #define se second #define pb push_back #define pi pair<int, int> #define vi vector<int> #define mod 1000000007 template<typename T> bool chkmin(T &a, T b){return (b < a) ? a = b, 1 : 0;} template<typename T> bool chkmax(T &a, T b){return (b > a) ? a = b, 1 : 0;} ll ksm(ll a, ll b) {if (b == 0) return 1; ll ns = ksm(a, b >> 1); ns = ns * ns % mod; if (b & 1) ns = ns * a % mod; return ns;} using namespace std; #define ar3 array<int, 3> const int maxn = 2e6 + 5; ar3 a; ar3 b; map<ar3, int> r; ar3 q[maxn]; int fr, ed; int ans[maxn]; int main() { for (int i = 0; i < maxn; i++) ans[i] = 1e9; for (int i = 0; i < 3; i++) cin >> a[i]; for (int i = 0; i < 3; i++) cin >> b[i]; q[ed++] = b; r[b] = 0; while (fr < ed) { ar3 x = q[fr++]; int cd = r[x]; for (int j = 0; j < 3; j++) chkmin(ans[x[j]], cd); for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { if (i == j) continue; int tot = x[i] + x[j]; for (int g = 0; g < 2; g++) { ar3 nx = x; nx[i] = g * a[i]; nx[j] = tot - nx[i]; if (nx[j] < 0 || nx[j] > a[j]) continue; if (!r.count(nx)) r[nx] = cd + 1, q[ed++] = nx; } } } for (int i = 0; i <= a[2]; i++) { if (ans[i] > 1e8) ans[i] = -1; printf("%d ", ans[i]); } return (0-0); // <3 cxr } /* 5 1 2 1 1 1 4 1 5 1 1*/ |