//Maciej Bielik #include<bits/stdc++.h> #define rep(i,poczatek,koniec) for(__typeof(koniec) i = poczatek; i<=koniec; ++i) #define repr(i,poczatek,koniec) for(__typeof(koniec) i = poczatek; i>=koniec; --i) #define pb push_back #define pob pop_back #define eb emplace_back #define pf push_front #define pof pop_front #define st first #define nd second #define bend(X) X.begin(),X.end() #define sz(X) (int(X.size())) #define print cout<< #ifdef LOCAL #define nl endl #define dbg if(1)cout<< #else #define nl '\n' #define dbg if(0)cout<< #endif using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair<int,int>; using pll = pair<ll,ll>; using pli = pair<ll,int>; using vb = vector<bool>; using vc = vector<char>; using vi = vector<int>; using vl = vector<ll>; using vpi = vector<pii>; using vpl = vector<pll>; using vvi = vector<vi>; using vvl = vector<vl>; using vvb = vector<vb>; template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& x){ is >> x.st >> x.nd; return is; } template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& x){ os << '(' << x.st << ',' << x.nd << ')'; return os; } template<typename T> istream& operator>>(istream& is, vector<T>& x){ for(T& i : x)is >> i; return is; } template<typename T> ostream& operator<<(ostream& os, vector<T> x){ for(T& i : x)os << i << ' '; return os; } template<typename T1, typename T2> pair<T1,T2> operator+(const pair<T1,T2>& A, const pair<T1,T2>& B){ return {A.st + B.st, A.nd + B.nd}; } template<typename T1, typename T2> pair<T1,T2> operator-(const pair<T1,T2>& A, const pair<T1,T2>& B){ return {A.st - B.st, A.nd - B.nd}; } template<typename T1, typename T2> pair<T1,T2> operator-(const pair<T1,T2>& A){ return {-A.st, -A.nd}; } template<typename T1, typename T2> void mine(T1& A, const T2& B){if(B < A) A = B;} template<typename T1, typename T2> void maxe(T1& A, const T2& B){if(B > A) A = B;} const int INF = (int)2e9; const int war17 = (int)1<<17; const int war18 = (int)1<<18; const int war19 = (int)1<<19; const int war20 = (int)1<<20; const int war21 = (int)1<<21; const ll INFll = (ll)9e18; const int MOD = (int)1e9+7; int R(int pocz, int kon){ return (rand()%(kon-pocz+1) + pocz); } ll RR(ll pocz, ll kon){ return ((ll((rand()) << 30) + rand())/(kon-pocz+1) + pocz); } void fastDataTransfer(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const int N = 300005; int n, m, a, b, c, d, q; vi V; int A,B,C; set<pair<int,pii>>S; queue<pair<pii,pii>>Q; int ans[N]; int maxi[5]; int act[5]; void read(){ cin >> maxi[1] >> maxi[2] >> maxi[3]; cin >> a >> b >> c; rep(i,0,maxi[3]*3+2) ans[i] = -1; Q.push({{0,a},{b,c}}); } void ustaw(int ile, int val){ if(ans[val] == -1) ans[val] = ile; } void przelej(int p, int k){ if(act[k] == maxi[k]) return; int ile = min(maxi[k] - act[k], act[p]); int poma = act[1],pomb = act[2],pomc = act[3]; if(p == 1) poma -= ile; if(p == 2) pomb -= ile; if(p == 3) pomc -= ile; if(k == 1) poma += ile; if(k == 2) pomb += ile; if(k == 3) pomc += ile; if(S.count({poma,{pomb,pomc}})) return; Q.push({{act[0],poma},{pomb,pomc}}); } void oblicz(){ if(Q.size() == 0) return; auto pom = Q.front(); Q.pop(); act[0] = pom.st.st + 1; act[1] = pom.st.nd; act[2] = pom.nd.st; act[3] = pom.nd.nd; // print act[0] << ' ' << act[1] << ' ' << act[2] << ' ' << act[3] << nl; if (S.count({act[1],{act[2],act[3]}}) == 0){ S.insert({act[1],{act[2],act[3]}}); rep(i,1,3) ustaw(act[0]-1, act[i]); rep(i,1,3){ rep(j,1,3){ if(i != j) przelej(i,j); } } } oblicz(); } void solve(){ oblicz(); rep(i,0,maxi[3]){ print ans[i] << ' '; } print nl; } int main(){ fastDataTransfer(); int testCases = 1; // cin >> testCases; rep(testNumber, 1, testCases){ read(); solve(); } }
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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | //Maciej Bielik #include<bits/stdc++.h> #define rep(i,poczatek,koniec) for(__typeof(koniec) i = poczatek; i<=koniec; ++i) #define repr(i,poczatek,koniec) for(__typeof(koniec) i = poczatek; i>=koniec; --i) #define pb push_back #define pob pop_back #define eb emplace_back #define pf push_front #define pof pop_front #define st first #define nd second #define bend(X) X.begin(),X.end() #define sz(X) (int(X.size())) #define print cout<< #ifdef LOCAL #define nl endl #define dbg if(1)cout<< #else #define nl '\n' #define dbg if(0)cout<< #endif using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair<int,int>; using pll = pair<ll,ll>; using pli = pair<ll,int>; using vb = vector<bool>; using vc = vector<char>; using vi = vector<int>; using vl = vector<ll>; using vpi = vector<pii>; using vpl = vector<pll>; using vvi = vector<vi>; using vvl = vector<vl>; using vvb = vector<vb>; template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& x){ is >> x.st >> x.nd; return is; } template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& x){ os << '(' << x.st << ',' << x.nd << ')'; return os; } template<typename T> istream& operator>>(istream& is, vector<T>& x){ for(T& i : x)is >> i; return is; } template<typename T> ostream& operator<<(ostream& os, vector<T> x){ for(T& i : x)os << i << ' '; return os; } template<typename T1, typename T2> pair<T1,T2> operator+(const pair<T1,T2>& A, const pair<T1,T2>& B){ return {A.st + B.st, A.nd + B.nd}; } template<typename T1, typename T2> pair<T1,T2> operator-(const pair<T1,T2>& A, const pair<T1,T2>& B){ return {A.st - B.st, A.nd - B.nd}; } template<typename T1, typename T2> pair<T1,T2> operator-(const pair<T1,T2>& A){ return {-A.st, -A.nd}; } template<typename T1, typename T2> void mine(T1& A, const T2& B){if(B < A) A = B;} template<typename T1, typename T2> void maxe(T1& A, const T2& B){if(B > A) A = B;} const int INF = (int)2e9; const int war17 = (int)1<<17; const int war18 = (int)1<<18; const int war19 = (int)1<<19; const int war20 = (int)1<<20; const int war21 = (int)1<<21; const ll INFll = (ll)9e18; const int MOD = (int)1e9+7; int R(int pocz, int kon){ return (rand()%(kon-pocz+1) + pocz); } ll RR(ll pocz, ll kon){ return ((ll((rand()) << 30) + rand())/(kon-pocz+1) + pocz); } void fastDataTransfer(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const int N = 300005; int n, m, a, b, c, d, q; vi V; int A,B,C; set<pair<int,pii>>S; queue<pair<pii,pii>>Q; int ans[N]; int maxi[5]; int act[5]; void read(){ cin >> maxi[1] >> maxi[2] >> maxi[3]; cin >> a >> b >> c; rep(i,0,maxi[3]*3+2) ans[i] = -1; Q.push({{0,a},{b,c}}); } void ustaw(int ile, int val){ if(ans[val] == -1) ans[val] = ile; } void przelej(int p, int k){ if(act[k] == maxi[k]) return; int ile = min(maxi[k] - act[k], act[p]); int poma = act[1],pomb = act[2],pomc = act[3]; if(p == 1) poma -= ile; if(p == 2) pomb -= ile; if(p == 3) pomc -= ile; if(k == 1) poma += ile; if(k == 2) pomb += ile; if(k == 3) pomc += ile; if(S.count({poma,{pomb,pomc}})) return; Q.push({{act[0],poma},{pomb,pomc}}); } void oblicz(){ if(Q.size() == 0) return; auto pom = Q.front(); Q.pop(); act[0] = pom.st.st + 1; act[1] = pom.st.nd; act[2] = pom.nd.st; act[3] = pom.nd.nd; // print act[0] << ' ' << act[1] << ' ' << act[2] << ' ' << act[3] << nl; if (S.count({act[1],{act[2],act[3]}}) == 0){ S.insert({act[1],{act[2],act[3]}}); rep(i,1,3) ustaw(act[0]-1, act[i]); rep(i,1,3){ rep(j,1,3){ if(i != j) przelej(i,j); } } } oblicz(); } void solve(){ oblicz(); rep(i,0,maxi[3]){ print ans[i] << ' '; } print nl; } int main(){ fastDataTransfer(); int testCases = 1; // cin >> testCases; rep(testNumber, 1, testCases){ read(); solve(); } } |