#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define pb push_back #define debug(x) cout << #x << " " << x << endl #define all(x) x.begin(),x.end() #define ll long long #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define vll vector<ll> #define vvll vector<vll> #define ld long double #define ull unsigned long long #define vull vector<ull> #define fi first #define se second #define PII pair<int,int> #define vPII vector<PII> #define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());} #define int128 __int128 int ans[100005]; int A,B,C; map<tuple<int,int,int>,int> mapka; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); // cout << setprecision(16) << fixed; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int tt = 1; // cin >> tt; while(tt--) { int a,b,c; cin >> A >> B >> C >> a >> b >> c; rep(i,C+1) ans[i] = INT_MAX; mapka[{a,b,c}] = 1; queue<tuple<int,int,int>> kol; kol.push({a,b,c}); while(!kol.empty()){ tie(a,b,c) = kol.front(); kol.pop(); int kt = mapka[{a,b,c}]; ans[a] = min(ans[a], kt-1); ans[b] = min(ans[b], kt-1); ans[c] = min(ans[c], kt-1); int ile = min(B-b,a); tuple<int,int,int> tup = {a-ile,b+ile,c}; int x = mapka[tup]; if(x == 0 or kt+1 < x){ mapka[tup] = kt+1; kol.push(tup); } ile = min(C-c,a); tup = {a-ile,b,c+ile}; x = mapka[tup]; if(x == 0 or kt+1 < x){ mapka[tup] = kt+1; kol.push(tup); } ile = min(A-a,b); tup = {a+ile,b-ile,c}; x = mapka[tup]; if(x == 0 or kt+1 < x){ mapka[tup] = kt+1; kol.push(tup); } ile = min(C-c,b); tup = {a,b-ile,c+ile}; x = mapka[tup]; if(x == 0 or kt+1 < x){ mapka[tup] = kt+1; kol.push(tup); } ile = min(A-a,c); tup = {a+ile,b,c-ile}; x = mapka[tup]; if(x == 0 or kt+1 < x){ mapka[tup] = kt+1; kol.push(tup); } ile = min(B-b,c); tup = {a,b+ile,c-ile}; x = mapka[tup]; if(x == 0 or kt+1 < x){ mapka[tup] = kt+1; kol.push(tup); } } rep(i,C+1){ if(ans[i] == INT_MAX) cout << -1; else cout << ans[i]; if(i < C) cout << " "; } } }
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 | #include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define pb push_back #define debug(x) cout << #x << " " << x << endl #define all(x) x.begin(),x.end() #define ll long long #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define vll vector<ll> #define vvll vector<vll> #define ld long double #define ull unsigned long long #define vull vector<ull> #define fi first #define se second #define PII pair<int,int> #define vPII vector<PII> #define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());} #define int128 __int128 int ans[100005]; int A,B,C; map<tuple<int,int,int>,int> mapka; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); // cout << setprecision(16) << fixed; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int tt = 1; // cin >> tt; while(tt--) { int a,b,c; cin >> A >> B >> C >> a >> b >> c; rep(i,C+1) ans[i] = INT_MAX; mapka[{a,b,c}] = 1; queue<tuple<int,int,int>> kol; kol.push({a,b,c}); while(!kol.empty()){ tie(a,b,c) = kol.front(); kol.pop(); int kt = mapka[{a,b,c}]; ans[a] = min(ans[a], kt-1); ans[b] = min(ans[b], kt-1); ans[c] = min(ans[c], kt-1); int ile = min(B-b,a); tuple<int,int,int> tup = {a-ile,b+ile,c}; int x = mapka[tup]; if(x == 0 or kt+1 < x){ mapka[tup] = kt+1; kol.push(tup); } ile = min(C-c,a); tup = {a-ile,b,c+ile}; x = mapka[tup]; if(x == 0 or kt+1 < x){ mapka[tup] = kt+1; kol.push(tup); } ile = min(A-a,b); tup = {a+ile,b-ile,c}; x = mapka[tup]; if(x == 0 or kt+1 < x){ mapka[tup] = kt+1; kol.push(tup); } ile = min(C-c,b); tup = {a,b-ile,c+ile}; x = mapka[tup]; if(x == 0 or kt+1 < x){ mapka[tup] = kt+1; kol.push(tup); } ile = min(A-a,c); tup = {a+ile,b,c-ile}; x = mapka[tup]; if(x == 0 or kt+1 < x){ mapka[tup] = kt+1; kol.push(tup); } ile = min(B-b,c); tup = {a,b+ile,c-ile}; x = mapka[tup]; if(x == 0 or kt+1 < x){ mapka[tup] = kt+1; kol.push(tup); } } rep(i,C+1){ if(ans[i] == INT_MAX) cout << -1; else cout << ans[i]; if(i < C) cout << " "; } } } |