#include<bits/stdc++.h> #define _ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define PB push_back #define ST first #define ND second using namespace std; const int MAXN=(1e5+5); using pi= pair< pair<int,int>, int >; int A,B,C, a,b,c; int ans[MAXN]; map< pi, int > odw; queue< pair<pi , int > > q; void propagate(pi x, int val){ //if(x.ST.ST == a && x.ST.ND == b && x.ND == c) return; odw[x]=val; int a1=x.ST.ST, b1=x.ST.ND, c1=x.ND; ans[a1]=min(ans[a1], val); ans[b1]=min(ans[b1], val); ans[c1]=min(ans[c1], val); if(a1+b1 <= B){ if(odw[{{0,a1+b1},c1}]==0) q.push({{{0,a1+b1},c1}, val+1}); } if(a1+c1 <= C){ if(odw[{{0,b1},a1+c1}]==0) q.push({{{0,b1},a1+c1}, val+1}); } if(a1+b1 <= A){ if(odw[{{a1+b1,0},c1}]==0) q.push({{{a1+b1,0},c1}, val+1}); } if(a1+c1 <= A){ if(odw[{{a1+c1,b1},0}]==0) q.push({{{a1+c1,b1},0}, val+1}); } if(c1+b1 <= C){ if(odw[{{a1,0},b1+c1}]==0) q.push({{{a1,0},b1+c1}, val+1}); } if(b1+c1 <= B){ if(odw[{{a1,b1+c1},0}]==0) q.push({{{a1,b1+c1},0}, val+1}); } if(a1+b1 > B){ if(odw[{{a1+b1-B,B},c1}]==0) q.push({{{a1+b1-B,B},c1}, val+1}); } if(a1+c1 > C){ if(odw[{{a1+c1-C,b1},C}]==0) q.push({{{a1+c1-C,b1},C}, val+1}); } if(a1+b1 > A){ if(odw[{{A,a1+b1-A},c1}]==0) q.push({{{A,a1+b1-A},c1}, val+1}); } if(a1+c1 > A){ if(odw[{{A,b1},a1+c1-A}]==0) q.push({{{A,b1},a1+c1-A}, val+1}); } if(c1+b1 > C){ if(odw[{{a1,c1+b1-C},C}]==0) q.push({{{a1,c1+b1-C},C}, val+1}); } if(b1+c1 > B){ if(odw[{{a1,B},b1+c1-B}]==0) q.push({{{a1,B},b1+c1-B}, val+1}); } } int main() { _ cin>>A>>B>>C>>a>>b>>c; for(int i=0; i<=C; i++) ans[i]=10*MAXN; odw[{{a,b},c}]=0; q.push({{{a,b},c},0}); while(!q.empty()){ pi x=q.front().ST; int wyn=q.front().ND; q.pop(); propagate(x, wyn); } for(int i=0; i<=C; i++){ if(ans[i]==10*MAXN) cout<<"-1 "; else cout<<ans[i]<<" "; } }
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 | #include<bits/stdc++.h> #define _ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define PB push_back #define ST first #define ND second using namespace std; const int MAXN=(1e5+5); using pi= pair< pair<int,int>, int >; int A,B,C, a,b,c; int ans[MAXN]; map< pi, int > odw; queue< pair<pi , int > > q; void propagate(pi x, int val){ //if(x.ST.ST == a && x.ST.ND == b && x.ND == c) return; odw[x]=val; int a1=x.ST.ST, b1=x.ST.ND, c1=x.ND; ans[a1]=min(ans[a1], val); ans[b1]=min(ans[b1], val); ans[c1]=min(ans[c1], val); if(a1+b1 <= B){ if(odw[{{0,a1+b1},c1}]==0) q.push({{{0,a1+b1},c1}, val+1}); } if(a1+c1 <= C){ if(odw[{{0,b1},a1+c1}]==0) q.push({{{0,b1},a1+c1}, val+1}); } if(a1+b1 <= A){ if(odw[{{a1+b1,0},c1}]==0) q.push({{{a1+b1,0},c1}, val+1}); } if(a1+c1 <= A){ if(odw[{{a1+c1,b1},0}]==0) q.push({{{a1+c1,b1},0}, val+1}); } if(c1+b1 <= C){ if(odw[{{a1,0},b1+c1}]==0) q.push({{{a1,0},b1+c1}, val+1}); } if(b1+c1 <= B){ if(odw[{{a1,b1+c1},0}]==0) q.push({{{a1,b1+c1},0}, val+1}); } if(a1+b1 > B){ if(odw[{{a1+b1-B,B},c1}]==0) q.push({{{a1+b1-B,B},c1}, val+1}); } if(a1+c1 > C){ if(odw[{{a1+c1-C,b1},C}]==0) q.push({{{a1+c1-C,b1},C}, val+1}); } if(a1+b1 > A){ if(odw[{{A,a1+b1-A},c1}]==0) q.push({{{A,a1+b1-A},c1}, val+1}); } if(a1+c1 > A){ if(odw[{{A,b1},a1+c1-A}]==0) q.push({{{A,b1},a1+c1-A}, val+1}); } if(c1+b1 > C){ if(odw[{{a1,c1+b1-C},C}]==0) q.push({{{a1,c1+b1-C},C}, val+1}); } if(b1+c1 > B){ if(odw[{{a1,B},b1+c1-B}]==0) q.push({{{a1,B},b1+c1-B}, val+1}); } } int main() { _ cin>>A>>B>>C>>a>>b>>c; for(int i=0; i<=C; i++) ans[i]=10*MAXN; odw[{{a,b},c}]=0; q.push({{{a,b},c},0}); while(!q.empty()){ pi x=q.front().ST; int wyn=q.front().ND; q.pop(); propagate(x, wyn); } for(int i=0; i<=C; i++){ if(ans[i]==10*MAXN) cout<<"-1 "; else cout<<ans[i]<<" "; } } |