#include<bits/stdc++.h> //#pragma GCC optimize("Ofast") //#pragma GCC optimize("trapv") #define st first #define nd second #define pb(x) push_back(x) #define pp(x) pop_back(x) #define mp(a, b) make_pair(a, b) #define all(x) (x).begin(), (x).end() #define rev(x) reverse(all(x)) #define sor(x) sort(all(x)) #define sz(x) (int)(x).size() #define rsz(x) resize(x) using namespace std; ///~~~~~~~~~~~~~~~~~~~~~~~~~~ void debug(){cerr<<"\n";} template <typename H, typename... T> void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);} #define deb(x...) cerr<<#x<<" = ";debug(x); ///~~~~~~~~~~~~~~~~~~~~~~~~~ typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<pii > vii; typedef vector<ll> vl; typedef vector<pll> vll; typedef string str; #define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const int N=2e5+5, INF=1e9+5, mod=1e9+7; int main(){ //BOOST; int A, B, C, a, b, c; vi cap(3); cin>>cap[0]>>cap[1]>>cap[2]>>a>>b>>c; map<array<int, 3>, int> d; d[{a, b, c}]=1; vector<array<int, 3> > V; V.push_back({a, b, c}); vi ans(cap[2]+1, INF); for(int i=0; i<V.size(); i++){ auto v=V[i]; int D=d[v]; auto v2=v; for(int j=0; j<3; j++){ ans[v[j]]=min(ans[v[j]], D); for(int k=0; k<3; k++){ if(j==k)continue; v2=v; v2[j]=min(v[k]+v[j], cap[j]); v2[k]=v[k]+v[j]-v2[j]; if(d.find(v2)==d.end()){ V.pb(v2); d[v2]=D+1; } } } } for(int i=0; i<=cap[2]; i++){ if(ans[i]==INF)cout<<"-1 "; else cout<<ans[i]-1<<" "; } }
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 | #include<bits/stdc++.h> //#pragma GCC optimize("Ofast") //#pragma GCC optimize("trapv") #define st first #define nd second #define pb(x) push_back(x) #define pp(x) pop_back(x) #define mp(a, b) make_pair(a, b) #define all(x) (x).begin(), (x).end() #define rev(x) reverse(all(x)) #define sor(x) sort(all(x)) #define sz(x) (int)(x).size() #define rsz(x) resize(x) using namespace std; ///~~~~~~~~~~~~~~~~~~~~~~~~~~ void debug(){cerr<<"\n";} template <typename H, typename... T> void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);} #define deb(x...) cerr<<#x<<" = ";debug(x); ///~~~~~~~~~~~~~~~~~~~~~~~~~ typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<pii > vii; typedef vector<ll> vl; typedef vector<pll> vll; typedef string str; #define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const int N=2e5+5, INF=1e9+5, mod=1e9+7; int main(){ //BOOST; int A, B, C, a, b, c; vi cap(3); cin>>cap[0]>>cap[1]>>cap[2]>>a>>b>>c; map<array<int, 3>, int> d; d[{a, b, c}]=1; vector<array<int, 3> > V; V.push_back({a, b, c}); vi ans(cap[2]+1, INF); for(int i=0; i<V.size(); i++){ auto v=V[i]; int D=d[v]; auto v2=v; for(int j=0; j<3; j++){ ans[v[j]]=min(ans[v[j]], D); for(int k=0; k<3; k++){ if(j==k)continue; v2=v; v2[j]=min(v[k]+v[j], cap[j]); v2[k]=v[k]+v[j]-v2[j]; if(d.find(v2)==d.end()){ V.pb(v2); d[v2]=D+1; } } } } for(int i=0; i<=cap[2]; i++){ if(ans[i]==INF)cout<<"-1 "; else cout<<ans[i]-1<<" "; } } |