// Karol Kosinski 2021 #include <bits/stdc++.h> #define ENABLE_DEBUG #define FOR(i,a,b) for(int i=(a),_b=(b);i<_b;++i) #define FR_(i,a,b) for(int i=(a),_b=(b);i<=_b;++i) #define FD_(i,b,a) for(int i=(b),_a=(a);i>=_a;--i) #define ALL(c) (c).begin(),(c).end() #define SIZE(c) int((c).size()) #define TIE(x...) int x;tie(x) #define X first #define Y second #ifndef ENABLE_DEBUG #define DEB(k,f,x...) #else #define DEB(k,f,x...) {if(k)printf("--------%4d : %s\n",__LINE__,__FUNCTION__);f(x);} #endif #define DEBL DEB(1,void,0) #define DEBF(f,x...) DEB(1,f,x) #define DEBUG(x...) DEB(0,printf,x) using namespace std; using LL = long long; using ULL = unsigned long long; using PII = pair<int, int>; using TIII = tuple<int, int, int>; const int NX = 100'005; map<TIII, int> M; queue<TIII> Q; bool Was[NX]; int Res[NX]; int main() { int a, b, c, a0, b0, c0; scanf("%d%d%d%d%d%d", &a, &b, &c, &a0, &b0, &c0); int counter = c + 1; auto s = make_tuple(a0, b0, c0); M[s] = 0; Q.push(s); while ( not Q.empty() and counter > 0 ) { auto q = Q.front(); Q.pop(); TIE(x, y, z) = q; int d = M[q]; if ( not Was[x] ) { Res[x] = d; Was[x] = true; -- counter; } if ( not Was[y] ) { Res[y] = d; Was[y] = true; -- counter; } if ( not Was[z] ) { Res[z] = d; Was[z] = true; -- counter; } if ( 0 < x and y < b ) { int y1 = min(x + y, b); int x1 = x + y - y1; auto t = make_tuple(x1, y1, z); if ( M.find(t) == M.end() ) { M[t] = d + 1; Q.push(t); } } if ( 0 < y and x < a ) { int x1 = min(x + y, a); int y1 = x + y - x1; auto t = make_tuple(x1, y1, z); if ( M.find(t) == M.end() ) { M[t] = d + 1; Q.push(t); } } if ( 0 < x and z < c ) { int z1 = min(x + z, c); int x1 = x + z - z1; auto t = make_tuple(x1, y, z1); if ( M.find(t) == M.end() ) { M[t] = d + 1; Q.push(t); } } if ( 0 < z and x < a ) { int x1 = min(x + z, a); int z1 = x + z - x1; auto t = make_tuple(x1, y, z1); if ( M.find(t) == M.end() ) { M[t] = d + 1; Q.push(t); } } if ( 0 < y and z < c ) { int z1 = min(y + z, c); int y1 = y + z - z1; auto t = make_tuple(x, y1, z1); if ( M.find(t) == M.end() ) { M[t] = d + 1; Q.push(t); } } if ( 0 < z and y < b ) { int y1 = min(y + z, b); int z1 = y + z - y1; auto t = make_tuple(x, y1, z1); if ( M.find(t) == M.end() ) { M[t] = d + 1; Q.push(t); } } } FOR(i,0, c + 1 ) { if ( Was[i] ) printf("%d ", Res[i]); else printf("-1 "); } printf("\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 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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | // Karol Kosinski 2021 #include <bits/stdc++.h> #define ENABLE_DEBUG #define FOR(i,a,b) for(int i=(a),_b=(b);i<_b;++i) #define FR_(i,a,b) for(int i=(a),_b=(b);i<=_b;++i) #define FD_(i,b,a) for(int i=(b),_a=(a);i>=_a;--i) #define ALL(c) (c).begin(),(c).end() #define SIZE(c) int((c).size()) #define TIE(x...) int x;tie(x) #define X first #define Y second #ifndef ENABLE_DEBUG #define DEB(k,f,x...) #else #define DEB(k,f,x...) {if(k)printf("--------%4d : %s\n",__LINE__,__FUNCTION__);f(x);} #endif #define DEBL DEB(1,void,0) #define DEBF(f,x...) DEB(1,f,x) #define DEBUG(x...) DEB(0,printf,x) using namespace std; using LL = long long; using ULL = unsigned long long; using PII = pair<int, int>; using TIII = tuple<int, int, int>; const int NX = 100'005; map<TIII, int> M; queue<TIII> Q; bool Was[NX]; int Res[NX]; int main() { int a, b, c, a0, b0, c0; scanf("%d%d%d%d%d%d", &a, &b, &c, &a0, &b0, &c0); int counter = c + 1; auto s = make_tuple(a0, b0, c0); M[s] = 0; Q.push(s); while ( not Q.empty() and counter > 0 ) { auto q = Q.front(); Q.pop(); TIE(x, y, z) = q; int d = M[q]; if ( not Was[x] ) { Res[x] = d; Was[x] = true; -- counter; } if ( not Was[y] ) { Res[y] = d; Was[y] = true; -- counter; } if ( not Was[z] ) { Res[z] = d; Was[z] = true; -- counter; } if ( 0 < x and y < b ) { int y1 = min(x + y, b); int x1 = x + y - y1; auto t = make_tuple(x1, y1, z); if ( M.find(t) == M.end() ) { M[t] = d + 1; Q.push(t); } } if ( 0 < y and x < a ) { int x1 = min(x + y, a); int y1 = x + y - x1; auto t = make_tuple(x1, y1, z); if ( M.find(t) == M.end() ) { M[t] = d + 1; Q.push(t); } } if ( 0 < x and z < c ) { int z1 = min(x + z, c); int x1 = x + z - z1; auto t = make_tuple(x1, y, z1); if ( M.find(t) == M.end() ) { M[t] = d + 1; Q.push(t); } } if ( 0 < z and x < a ) { int x1 = min(x + z, a); int z1 = x + z - x1; auto t = make_tuple(x1, y, z1); if ( M.find(t) == M.end() ) { M[t] = d + 1; Q.push(t); } } if ( 0 < y and z < c ) { int z1 = min(y + z, c); int y1 = y + z - z1; auto t = make_tuple(x, y1, z1); if ( M.find(t) == M.end() ) { M[t] = d + 1; Q.push(t); } } if ( 0 < z and y < b ) { int y1 = min(y + z, b); int z1 = y + z - y1; auto t = make_tuple(x, y1, z1); if ( M.find(t) == M.end() ) { M[t] = d + 1; Q.push(t); } } } FOR(i,0, c + 1 ) { if ( Was[i] ) printf("%d ", Res[i]); else printf("-1 "); } printf("\n"); return 0; } |