#define pb push_back #define mp make_pair #define fi first #define se second #define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__) #define boost {ios_base::sync_with_stdio(false); cin.tie(); cout.tie();} #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector <int> vi; typedef pair<int,int> PII; typedef pair<ll,ll> PLL; constexpr ll nax = 1e6+6969, INF = 2e9+6969; int cap[3], dp[nax]; set <pair<int, PII>> vis; int main() { int a, b, c; for(int i=0;i<3;i++) scanf("%d", &cap[i]); scanf("%d%d%d", &a, &b, &c); queue <pair<PII, PII>> q; q.push(mp(mp(0, a), mp(b, c))); for(int i=0;i<=cap[2];i++) dp[i] = INF; dp[a] = dp[b] = dp[c] = 0; vis.insert(mp(a, mp(b, c))); while(!q.empty()) { int wyn = q.front().fi.fi; int cur[3]; cur[0] = q.front().fi.se; cur[1] = q.front().se.fi; cur[2] = q.front().se.se; q.pop(); for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { if(i == j) continue; int oldi, oldj; oldi = cur[i]; oldj = cur[j]; int tmp = min(cap[j] - cur[j], cur[i]); cur[i] -= tmp; cur[j] += tmp; if(vis.find(mp(cur[0], mp(cur[1], cur[2]))) == vis.end()) { for(int k = 0; k < 3; k++) dp[cur[k]] = min(dp[cur[k]], wyn + 1); vis.insert(mp(cur[0], mp(cur[1], cur[2]))); q.push(mp(mp(wyn+1, cur[0]), mp(cur[1], cur[2]))); } cur[i] = oldi; cur[j] = oldj; } } } for(int i=0;i<=cap[2];i++) printf("%d ", (dp[i] == INF ? -1 : dp[i])); puts(""); 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 | #define pb push_back #define mp make_pair #define fi first #define se second #define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__) #define boost {ios_base::sync_with_stdio(false); cin.tie(); cout.tie();} #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector <int> vi; typedef pair<int,int> PII; typedef pair<ll,ll> PLL; constexpr ll nax = 1e6+6969, INF = 2e9+6969; int cap[3], dp[nax]; set <pair<int, PII>> vis; int main() { int a, b, c; for(int i=0;i<3;i++) scanf("%d", &cap[i]); scanf("%d%d%d", &a, &b, &c); queue <pair<PII, PII>> q; q.push(mp(mp(0, a), mp(b, c))); for(int i=0;i<=cap[2];i++) dp[i] = INF; dp[a] = dp[b] = dp[c] = 0; vis.insert(mp(a, mp(b, c))); while(!q.empty()) { int wyn = q.front().fi.fi; int cur[3]; cur[0] = q.front().fi.se; cur[1] = q.front().se.fi; cur[2] = q.front().se.se; q.pop(); for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { if(i == j) continue; int oldi, oldj; oldi = cur[i]; oldj = cur[j]; int tmp = min(cap[j] - cur[j], cur[i]); cur[i] -= tmp; cur[j] += tmp; if(vis.find(mp(cur[0], mp(cur[1], cur[2]))) == vis.end()) { for(int k = 0; k < 3; k++) dp[cur[k]] = min(dp[cur[k]], wyn + 1); vis.insert(mp(cur[0], mp(cur[1], cur[2]))); q.push(mp(mp(wyn+1, cur[0]), mp(cur[1], cur[2]))); } cur[i] = oldi; cur[j] = oldj; } } } for(int i=0;i<=cap[2];i++) printf("%d ", (dp[i] == INF ? -1 : dp[i])); puts(""); return 0; } |