#include <bits/stdc++.h> #define QED return 0;} #define main() int main(){ using namespace std; const int inf = 1000007; int odw[100007]; int A, B, C, a, b, c, xd; map <pair <int, pair <int, int>>, int> mapa; queue <pair <int, pair <int, int>>> q, q2; void f(int x, int y, int z, int cnt){ if(mapa[{x, {y, z}}] == 1) return; mapa[{x, {y, z}}] = 1; odw[x] = min(odw[x], cnt); odw[y] = min(odw[y], cnt); odw[z] = min(odw[z], cnt); q2.push({max(x - (B - y), 0), {min(B, y + x), z}}); q2.push({max(x - (C - z), 0), {y, min(C, z + x)}}); q2.push({min(A, x + y), {max(y - (A - x), 0), z}}); q2.push({x, {max(y - (C - z), 0), min(C, z + y)}}); q2.push({min(A, x + z), {y, max(z - (A - x), 0)}}); q2.push({x, {min(B, y + z), max(z - (B - y), 0)}}); } main() //ios_base::sync_with_stdio(0); //cin.tie(0); //cout.tie(0); //A = 1; a = 1; B = 1; b = 1; C = 1; c = 1; cin >> A >> B >> C >> a >> b >> c; for(int i = 0; i <= C; i++) odw[i] = inf; q2.push({a, {b, c}}); while(!q2.empty()){ swap(q, q2); while(!q.empty()){ f(q.front().first, q.front().second.first, q.front().second.second, xd); q.pop(); } xd++; } for(int i = 0; i <= C; i++){ if(odw[i] == inf) cout << -1; else cout << odw[i]; cout << ' '; } QED
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 | #include <bits/stdc++.h> #define QED return 0;} #define main() int main(){ using namespace std; const int inf = 1000007; int odw[100007]; int A, B, C, a, b, c, xd; map <pair <int, pair <int, int>>, int> mapa; queue <pair <int, pair <int, int>>> q, q2; void f(int x, int y, int z, int cnt){ if(mapa[{x, {y, z}}] == 1) return; mapa[{x, {y, z}}] = 1; odw[x] = min(odw[x], cnt); odw[y] = min(odw[y], cnt); odw[z] = min(odw[z], cnt); q2.push({max(x - (B - y), 0), {min(B, y + x), z}}); q2.push({max(x - (C - z), 0), {y, min(C, z + x)}}); q2.push({min(A, x + y), {max(y - (A - x), 0), z}}); q2.push({x, {max(y - (C - z), 0), min(C, z + y)}}); q2.push({min(A, x + z), {y, max(z - (A - x), 0)}}); q2.push({x, {min(B, y + z), max(z - (B - y), 0)}}); } main() //ios_base::sync_with_stdio(0); //cin.tie(0); //cout.tie(0); //A = 1; a = 1; B = 1; b = 1; C = 1; c = 1; cin >> A >> B >> C >> a >> b >> c; for(int i = 0; i <= C; i++) odw[i] = inf; q2.push({a, {b, c}}); while(!q2.empty()){ swap(q, q2); while(!q.empty()){ f(q.front().first, q.front().second.first, q.front().second.second, xd); q.pop(); } xd++; } for(int i = 0; i <= C; i++){ if(odw[i] == inf) cout << -1; else cout << odw[i]; cout << ' '; } QED |