#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; #define mp make_pair const int N = 1e5 + 7; int ans[N]; void upd(int a, int d) { if (!ans[a]) ans[a] = d + 1; else ans[a] = min(ans[a], d + 1); } int main() { int A, B, C; scanf("%d%d%d", &A, &B, &C); int a, b, c; scanf("%d%d%d", &a, &b, &c); int sum = a + b + c; map<pii, int> dist; dist[mp(a, b)] = 0; queue<pii> q; q.push(mp(a, b)); while (!q.empty()) { int d = dist[q.front()]; auto [a, b] = q.front(); q.pop(); int v = min(a, B - b); pii s {a - v, b + v}; if (!dist.count(s)) { dist[s] = d + 1; q.push(s); } v = min(b, A - a); s = {a + v, b - v}; if (!dist.count(s)) { dist[s] = d + 1; q.push(s); } int c = sum - a - b; v = min(a, C - c); s = {a - v, b}; if (!dist.count(s)) { dist[s] = d + 1; q.push(s); } v = min(c, A - a); s = {a + v, b}; if (!dist.count(s)) { dist[s] = d + 1; q.push(s); } v = min(b, C - c); s = {a, b - v}; if (!dist.count(s)) { dist[s] = d + 1; q.push(s); } v = min(c, B - b); s = {a, b + v}; if (!dist.count(s)) { dist[s] = d + 1; q.push(s); } } for (auto [v, d] : dist) { auto [a, b] = v; int c = sum - a - b; upd(a, d); upd(b, d); upd(c, d); } for (int i = 0; i <= C; ++i) printf("%d ", ans[i] - 1); 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; using pii = pair<int, int>; #define mp make_pair const int N = 1e5 + 7; int ans[N]; void upd(int a, int d) { if (!ans[a]) ans[a] = d + 1; else ans[a] = min(ans[a], d + 1); } int main() { int A, B, C; scanf("%d%d%d", &A, &B, &C); int a, b, c; scanf("%d%d%d", &a, &b, &c); int sum = a + b + c; map<pii, int> dist; dist[mp(a, b)] = 0; queue<pii> q; q.push(mp(a, b)); while (!q.empty()) { int d = dist[q.front()]; auto [a, b] = q.front(); q.pop(); int v = min(a, B - b); pii s {a - v, b + v}; if (!dist.count(s)) { dist[s] = d + 1; q.push(s); } v = min(b, A - a); s = {a + v, b - v}; if (!dist.count(s)) { dist[s] = d + 1; q.push(s); } int c = sum - a - b; v = min(a, C - c); s = {a - v, b}; if (!dist.count(s)) { dist[s] = d + 1; q.push(s); } v = min(c, A - a); s = {a + v, b}; if (!dist.count(s)) { dist[s] = d + 1; q.push(s); } v = min(b, C - c); s = {a, b - v}; if (!dist.count(s)) { dist[s] = d + 1; q.push(s); } v = min(c, B - b); s = {a, b + v}; if (!dist.count(s)) { dist[s] = d + 1; q.push(s); } } for (auto [v, d] : dist) { auto [a, b] = v; int c = sum - a - b; upd(a, d); upd(b, d); upd(c, d); } for (int i = 0; i <= C; ++i) printf("%d ", ans[i] - 1); return 0; } |