#include <bits/stdc++.h> #define bit(n, i) (((n)>>(i))&1LL) #define cat(x) cout << #x << " = " << x << "\n" #define pb push_back #define mp make_pair #define se second #define fi first #define inf 1000000000 #define llinf 2000000000000000000LL #define forn(i, a, b) for(ll i = (a); i <= (b); ++i) #define all(x) (x).begin(), (x).end() #define ppc(x) __builtin_popcount(x) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> i2; typedef vector<int> vi; typedef vector<ll> vll; template<typename T1, typename T2> void remax(T1& a, T2 b) { a = max(a, b); } template<typename T1, typename T2> void remin(T1& a, T2 b) { a = min(a, b); } typedef pair<i2, int> i3; const int N = 1e5+9; int ans[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int A, B, C, a, b, c; cin >> A >> B >> C >> a >> b >> c; queue<i3> Q; map<i3, int> D; Q.push(mp(mp(a, b), c)); D[mp(mp(a, b), c)] = 0; forn(i, 0, C) ans[i] = inf; while(!Q.empty()) { i3 u = Q.front(); Q.pop(); a = u.fi.fi; b = u.fi.se; c = u.se; int d = D[u]; remin(ans[a], d); remin(ans[b], d); remin(ans[c], d); if(a+b <= B && !D.count(mp(mp(0, a+b), c))) { D[mp(mp(0, a+b), c)] = d+1; Q.push(mp(mp(0, a+b), c)); } if(a+b > B && !D.count(mp(mp(a+b-B, B), c))) { D[mp(mp(a+b-B, B), c)] = d+1; Q.push(mp(mp(a+b-B, B), c)); } if(a+b <= A && !D.count(mp(mp(a+b, 0), c))) { D[mp(mp(a+b, 0), c)] = d+1; Q.push(mp(mp(a+b, 0), c)); } if(a+b > A && !D.count(mp(mp(A, a+b-A), c))) { D[mp(mp(A, a+b-A), c)] = d+1; Q.push(mp(mp(A, a+b-A), c)); } if(a+c <= C && !D.count(mp(mp(0, b), a+c))) { D[mp(mp(0, b), a+c)] = d+1; Q.push(mp(mp(0, b), a+c)); } if(a+c > C && !D.count(mp(mp(a+c-C, b), C))) { D[mp(mp(a+c-C, b), C)] = d+1; Q.push(mp(mp(a+c-C, b), C)); } if(a+c <= A && !D.count(mp(mp(a+c, b), 0))) { D[mp(mp(a+c, b), 0)] = d+1; Q.push(mp(mp(a+c, b), 0)); } if(a+c > A && !D.count(mp(mp(A, b), a+c-A))) { D[mp(mp(A, b), a+c-A)] = d+1; Q.push(mp(mp(A, b), a+c-A)); } if(b+c <= C && !D.count(mp(mp(a, 0), b+c))) { D[mp(mp(a, 0), b+c)] = d+1; Q.push(mp(mp(a, 0), b+c)); } if(b+c > C && !D.count(mp(mp(a, b+c-C), C))) { D[mp(mp(a, b+c-C), C)] = d+1; Q.push(mp(mp(a, b+c-C), C)); } if(b+c <= B && !D.count(mp(mp(a, b+c), 0))) { D[mp(mp(a, b+c), 0)] = d+1; Q.push(mp(mp(a, b+c), 0)); } if(b+c > B && !D.count(mp(mp(a, B), b+c-B))) { D[mp(mp(a, B), b+c-B)] = d+1; Q.push(mp(mp(a, B), b+c-B)); } } forn(i, 0, C) cout << ans[i] << " "; return 0; }
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | #include <bits/stdc++.h> #define bit(n, i) (((n)>>(i))&1LL) #define cat(x) cout << #x << " = " << x << "\n" #define pb push_back #define mp make_pair #define se second #define fi first #define inf 1000000000 #define llinf 2000000000000000000LL #define forn(i, a, b) for(ll i = (a); i <= (b); ++i) #define all(x) (x).begin(), (x).end() #define ppc(x) __builtin_popcount(x) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> i2; typedef vector<int> vi; typedef vector<ll> vll; template<typename T1, typename T2> void remax(T1& a, T2 b) { a = max(a, b); } template<typename T1, typename T2> void remin(T1& a, T2 b) { a = min(a, b); } typedef pair<i2, int> i3; const int N = 1e5+9; int ans[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int A, B, C, a, b, c; cin >> A >> B >> C >> a >> b >> c; queue<i3> Q; map<i3, int> D; Q.push(mp(mp(a, b), c)); D[mp(mp(a, b), c)] = 0; forn(i, 0, C) ans[i] = inf; while(!Q.empty()) { i3 u = Q.front(); Q.pop(); a = u.fi.fi; b = u.fi.se; c = u.se; int d = D[u]; remin(ans[a], d); remin(ans[b], d); remin(ans[c], d); if(a+b <= B && !D.count(mp(mp(0, a+b), c))) { D[mp(mp(0, a+b), c)] = d+1; Q.push(mp(mp(0, a+b), c)); } if(a+b > B && !D.count(mp(mp(a+b-B, B), c))) { D[mp(mp(a+b-B, B), c)] = d+1; Q.push(mp(mp(a+b-B, B), c)); } if(a+b <= A && !D.count(mp(mp(a+b, 0), c))) { D[mp(mp(a+b, 0), c)] = d+1; Q.push(mp(mp(a+b, 0), c)); } if(a+b > A && !D.count(mp(mp(A, a+b-A), c))) { D[mp(mp(A, a+b-A), c)] = d+1; Q.push(mp(mp(A, a+b-A), c)); } if(a+c <= C && !D.count(mp(mp(0, b), a+c))) { D[mp(mp(0, b), a+c)] = d+1; Q.push(mp(mp(0, b), a+c)); } if(a+c > C && !D.count(mp(mp(a+c-C, b), C))) { D[mp(mp(a+c-C, b), C)] = d+1; Q.push(mp(mp(a+c-C, b), C)); } if(a+c <= A && !D.count(mp(mp(a+c, b), 0))) { D[mp(mp(a+c, b), 0)] = d+1; Q.push(mp(mp(a+c, b), 0)); } if(a+c > A && !D.count(mp(mp(A, b), a+c-A))) { D[mp(mp(A, b), a+c-A)] = d+1; Q.push(mp(mp(A, b), a+c-A)); } if(b+c <= C && !D.count(mp(mp(a, 0), b+c))) { D[mp(mp(a, 0), b+c)] = d+1; Q.push(mp(mp(a, 0), b+c)); } if(b+c > C && !D.count(mp(mp(a, b+c-C), C))) { D[mp(mp(a, b+c-C), C)] = d+1; Q.push(mp(mp(a, b+c-C), C)); } if(b+c <= B && !D.count(mp(mp(a, b+c), 0))) { D[mp(mp(a, b+c), 0)] = d+1; Q.push(mp(mp(a, b+c), 0)); } if(b+c > B && !D.count(mp(mp(a, B), b+c-B))) { D[mp(mp(a, B), b+c-B)] = d+1; Q.push(mp(mp(a, B), b+c-B)); } } forn(i, 0, C) cout << ans[i] << " "; return 0; } |