#include <bits/stdc++.h> using namespace std; #define endl '\n' #define st first #define nd second #define pb push_back #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define ll long long ll mod=1000000007; int inf=1000000007; ll infl=1000000000000000007; bool odw[100007][2][3]; int d[100007]; int A,B,C; bool check(int a,int b,int c) { if(a==0) { if(odw[b][0][0]) return 0; odw[b][0][0]=1; return 1; } if(a==A) { if(odw[b][1][0]) return 0; odw[b][1][0]=1; return 1; } if(b==0) { if(odw[a][0][1]) return 0; odw[a][0][1]=1; return 1; } if(b==B) { if(odw[a][1][1]) return 0; odw[a][1][1]=1; return 1; } if(c==0) { if(odw[a][0][2]) return 0; odw[a][0][2]=1; return 1; } if(c==C) { if(odw[a][1][2]) return 0; odw[a][1][2]=1; return 1; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a,b,c; cin>>A>>B>>C>>a>>b>>c; deque<pair<pair<int,int>,pair<int,int>>>Q; memset(d,-1,sizeof d); Q.pb({{a,b},{c,0}}); while(!Q.empty()) { a=Q[0].st.st; b=Q[0].st.nd; c=Q[0].nd.st; int l=Q[0].nd.nd; Q.pop_front(); if(d[a]==-1) d[a]=l; if(d[b]==-1) d[b]=l; if(d[c]==-1) d[c]=l; int x; x=min(a,B-b);if(check(a-x,b+x,c)) Q.pb({{a-x,b+x},{c,l+1}}); x=min(a,C-c);if(check(a-x,b,c+x)) Q.pb({{a-x,b},{c+x,l+1}}); x=min(b,A-a);if(check(a+x,b-x,c)) Q.pb({{a+x,b-x},{c,l+1}}); x=min(b,C-c);if(check(a,b-x,c+x)) Q.pb({{a,b-x},{c+x,l+1}}); x=min(c,A-a);if(check(a+x,b,c-x)) Q.pb({{a+x,b},{c-x,l+1}}); x=min(c,B-b);if(check(a,b+x,c-x)) Q.pb({{a,b+x},{c-x,l+1}}); } for(int i=0;i<=C;i++) cout<<d[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 | #include <bits/stdc++.h> using namespace std; #define endl '\n' #define st first #define nd second #define pb push_back #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define ll long long ll mod=1000000007; int inf=1000000007; ll infl=1000000000000000007; bool odw[100007][2][3]; int d[100007]; int A,B,C; bool check(int a,int b,int c) { if(a==0) { if(odw[b][0][0]) return 0; odw[b][0][0]=1; return 1; } if(a==A) { if(odw[b][1][0]) return 0; odw[b][1][0]=1; return 1; } if(b==0) { if(odw[a][0][1]) return 0; odw[a][0][1]=1; return 1; } if(b==B) { if(odw[a][1][1]) return 0; odw[a][1][1]=1; return 1; } if(c==0) { if(odw[a][0][2]) return 0; odw[a][0][2]=1; return 1; } if(c==C) { if(odw[a][1][2]) return 0; odw[a][1][2]=1; return 1; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a,b,c; cin>>A>>B>>C>>a>>b>>c; deque<pair<pair<int,int>,pair<int,int>>>Q; memset(d,-1,sizeof d); Q.pb({{a,b},{c,0}}); while(!Q.empty()) { a=Q[0].st.st; b=Q[0].st.nd; c=Q[0].nd.st; int l=Q[0].nd.nd; Q.pop_front(); if(d[a]==-1) d[a]=l; if(d[b]==-1) d[b]=l; if(d[c]==-1) d[c]=l; int x; x=min(a,B-b);if(check(a-x,b+x,c)) Q.pb({{a-x,b+x},{c,l+1}}); x=min(a,C-c);if(check(a-x,b,c+x)) Q.pb({{a-x,b},{c+x,l+1}}); x=min(b,A-a);if(check(a+x,b-x,c)) Q.pb({{a+x,b-x},{c,l+1}}); x=min(b,C-c);if(check(a,b-x,c+x)) Q.pb({{a,b-x},{c+x,l+1}}); x=min(c,A-a);if(check(a+x,b,c-x)) Q.pb({{a+x,b},{c-x,l+1}}); x=min(c,B-b);if(check(a,b+x,c-x)) Q.pb({{a,b+x},{c-x,l+1}}); } for(int i=0;i<=C;i++) cout<<d[i]<<" "; return 0; } |