#include<bits/stdc++.h> using namespace std; const int INF = 1e9; using T = tuple<int,int,int>; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int A,B,C,a,b,c; cin >> A >> B >> C >> a >> b >> c; map<T,int> M; M[{a,b,c}] = 0; vector<int> result(C+1,INF); queue<T> q[2]; int r = 0; q[r].push({a,b,c}); do { while(!q[r].empty()) { tie(a,b,c) = q[r].front(); q[r].pop(); int v = M[{a,b,c}]; T u; u = {a+min(A-a,b),b-min(A-a,b),c}; if(M.find(u) == M.end()){ M[u] = v+1; q[1-r].push(u); } u = {a+min(A-a,c),b,c-min(A-a,c)}; if(M.find(u) == M.end()){ M[u] = v+1; q[1-r].push(u); } u = {a-min(B-b,a),b+min(B-b,a),c}; if(M.find(u) == M.end()){ M[u] = v+1; q[1-r].push(u); } u = {a,b+min(B-b,c),c-min(B-b,c)}; if(M.find(u) == M.end()){ M[u] = v+1; q[1-r].push(u); } u = {a-min(C-c,a),b,c+min(C-c,a)}; if(M.find(u) == M.end()){ M[u] = v+1; q[1-r].push(u); } u = {a,b-min(C-c,b),c+min(C-c,b)}; if(M.find(u) == M.end()){ M[u] = v+1; q[1-r].push(u); } } r = 1-r; } while(!q[r].empty()); for(auto [k,v] : M) { tie(a,b,c) = k; result[a] = min(result[a], v); result[b] = min(result[b], v); result[c] = min(result[c], v); } for(int i : result) cout << (i == INF ? -1 : i) << " "; cout << "\n"; 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 | #include<bits/stdc++.h> using namespace std; const int INF = 1e9; using T = tuple<int,int,int>; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int A,B,C,a,b,c; cin >> A >> B >> C >> a >> b >> c; map<T,int> M; M[{a,b,c}] = 0; vector<int> result(C+1,INF); queue<T> q[2]; int r = 0; q[r].push({a,b,c}); do { while(!q[r].empty()) { tie(a,b,c) = q[r].front(); q[r].pop(); int v = M[{a,b,c}]; T u; u = {a+min(A-a,b),b-min(A-a,b),c}; if(M.find(u) == M.end()){ M[u] = v+1; q[1-r].push(u); } u = {a+min(A-a,c),b,c-min(A-a,c)}; if(M.find(u) == M.end()){ M[u] = v+1; q[1-r].push(u); } u = {a-min(B-b,a),b+min(B-b,a),c}; if(M.find(u) == M.end()){ M[u] = v+1; q[1-r].push(u); } u = {a,b+min(B-b,c),c-min(B-b,c)}; if(M.find(u) == M.end()){ M[u] = v+1; q[1-r].push(u); } u = {a-min(C-c,a),b,c+min(C-c,a)}; if(M.find(u) == M.end()){ M[u] = v+1; q[1-r].push(u); } u = {a,b-min(C-c,b),c+min(C-c,b)}; if(M.find(u) == M.end()){ M[u] = v+1; q[1-r].push(u); } } r = 1-r; } while(!q[r].empty()); for(auto [k,v] : M) { tie(a,b,c) = k; result[a] = min(result[a], v); result[b] = min(result[b], v); result[c] = min(result[c], v); } for(int i : result) cout << (i == INF ? -1 : i) << " "; cout << "\n"; return 0; } |