// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
template<class C> void mini(C &a5, C b5) { a5 = min(a5, b5); }
template<class C> void maxi(C &a5, C b5) { a5 = max(a5, b5); }
#ifdef LOCAL
const bool debug = true;
#else
const bool debug = false;
#define cerr if (true) {} else cout
#endif
// clang-format on
//#define int long long
#define double long double
const int INF = 1e9;
const int mod = 1e9 + 7;
const int nax = 1e6;
int poj[3];
int res[nax];
struct My {
int zap[3];
int dist;
bool operator < (const My &other) const {
if (zap[0] == other.zap[0]) {
if (zap[1] == other.zap[1]) {
return zap[2] < other.zap[2];
}
return zap[1] < other.zap[1];
}
return zap[0] < other.zap[0];
}
};
set<My> visited;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
for (int i = 0; i < 3; i++) {
cin >> poj[i];
}
fill(res, res + poj[2] + 1, INF);
queue<My> kol;
int a, b, c;
cin >> a >> b >> c;
kol.push({{a, b, c}, 0});
visited.insert(kol.front());
while (!kol.empty()) {
My gdzie = kol.front();
kol.pop();
for (int i = 0; i < 3; i++) {
mini(res[gdzie.zap[i]], gdzie.dist);
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i == j) continue;
My to = gdzie;
int wyl = min(
gdzie.zap[i],
poj[j] - gdzie.zap[j]);
to.zap[i] -= wyl;
to.zap[j] += wyl;
to.dist++;
if (visited.insert(to).second) {
kol.push(to);
}
}
}
}
for (int i = 0; i <= poj[2]; i++) {
if (res[i] == INF) cout << "-1 ";
else cout << res[i] << " ";
}
cout << "\n";
return 0;
}/*
2 7 9
1 3 6
*/
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 | // clang-format off #include <bits/stdc++.h> using namespace std; #define ALL(x) (x).begin(), (x).end() template<class C> void mini(C &a5, C b5) { a5 = min(a5, b5); } template<class C> void maxi(C &a5, C b5) { a5 = max(a5, b5); } #ifdef LOCAL const bool debug = true; #else const bool debug = false; #define cerr if (true) {} else cout #endif // clang-format on //#define int long long #define double long double const int INF = 1e9; const int mod = 1e9 + 7; const int nax = 1e6; int poj[3]; int res[nax]; struct My { int zap[3]; int dist; bool operator < (const My &other) const { if (zap[0] == other.zap[0]) { if (zap[1] == other.zap[1]) { return zap[2] < other.zap[2]; } return zap[1] < other.zap[1]; } return zap[0] < other.zap[0]; } }; set<My> visited; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); for (int i = 0; i < 3; i++) { cin >> poj[i]; } fill(res, res + poj[2] + 1, INF); queue<My> kol; int a, b, c; cin >> a >> b >> c; kol.push({{a, b, c}, 0}); visited.insert(kol.front()); while (!kol.empty()) { My gdzie = kol.front(); kol.pop(); for (int i = 0; i < 3; i++) { mini(res[gdzie.zap[i]], gdzie.dist); } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i == j) continue; My to = gdzie; int wyl = min( gdzie.zap[i], poj[j] - gdzie.zap[j]); to.zap[i] -= wyl; to.zap[j] += wyl; to.dist++; if (visited.insert(to).second) { kol.push(to); } } } } for (int i = 0; i <= poj[2]; i++) { if (res[i] == INF) cout << "-1 "; else cout << res[i] << " "; } cout << "\n"; return 0; }/* 2 7 9 1 3 6 */ |
English