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
#include <iostream>
#include <list>
#include <set>
#include <bitset>
#include <vector>
#include <tuple>
#include <queue>

using namespace std;

typedef unsigned long long ull;


int main() {
    ios_base::sync_with_stdio(false);

    int ca, cb, cc, a, b, c;
    cin >> ca;
    cin >> cb;
    cin >> cc;
    cin >> a;
    cin >> b;
    cin >> c;

    vector<int> steps(cc + 1, INT32_MAX);
    queue<tuple<int, int, int, int>> q;

    set<tuple<int, int, int>> seen;

    q.push(make_tuple(a, b, c, 0));
    seen.insert(make_tuple(a, b, c));

    vector<tuple<int, int, int>> neigh;

    while (!q.empty()) {
        auto front = q.front();
        q.pop();

        a = get<0>(front);
        b = get<1>(front);
        c = get<2>(front);
        auto d = get<3>(front);

//        cout << "front: " << a << ", " << b << ", " << c << ", dist: " << d << endl;

        steps[a] = min(steps[a], d);
        steps[b] = min(steps[b], d);
        steps[c] = min(steps[c], d);

        // clear neighs
        neigh.clear();

        // b -> a
        neigh.emplace_back(make_tuple(min(ca, a + b), max(0, b - ca + a), c));

        // b -> c
        neigh.emplace_back(make_tuple(a, max(0, b - cc + c), min(cc, c + b)));

        // a -> b
        neigh.emplace_back(make_tuple(max(0, a - cb + b), min(cb, a + b), c));

        // a -> c
        neigh.emplace_back(make_tuple(max(0, a - cc + c), b, min(cc, a + c)));

        // c -> a
        neigh.emplace_back(make_tuple(min(ca, a + c), b, max(0, c - ca + a)));

        // c -> b
        neigh.emplace_back(make_tuple(a, min(cb, b + c), max(0, c - cb + b)));

        for (const auto &n: neigh) {
            if (seen.find(n) == seen.end()) {
                q.push(make_tuple(get<0>(n), get<1>(n), get<2>(n), d + 1));
                seen.insert(n);
            }
        }
    }

    for (int i = 0; i <= cc; i++) {
        if (steps[i] == INT32_MAX) {
            steps[i] = -1;
        }
        cout << steps[i] << " ";
    }
    cout << endl;
    return 0;
}