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
#include <bits/stdc++.h>

using namespace std;

const int N = 100'009;
const int inf = 1'000'000'007;

int A, B, C;
map<tuple<int, int, int>, int> vis;
int ans[N];

int cost;

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);

    int aa, bb, cc;
    cin >> A >> B >> C;
    cin >> aa >> bb >> cc;

    queue<tuple<int, int, int, int>> q;

    q.push({aa, bb, cc, 0});

    while(q.size()) {

        auto add = [&q](int new_a, int new_b, int new_c, int cost) {

            if(vis.count(tie(new_a, new_b, new_c)) == 0) {
                vis[tie(new_a, new_b, new_c)] = cost;
                q.push(tie(new_a, new_b, new_c, cost));                
            }

        };

        int a, b, c, cost;
        tie(a, b, c, cost) = q.front(); q.pop();

        add(a - min(B - b, a), b + min(B - b, a), c, cost + 1);
        add(a + min(A - a, b), b - min(A - a, b), c, cost + 1);

        add(a - min(C - c, a), b, c + min(C - c, a), cost + 1);
        add(a + min(A - a, c), b, c - min(A - a, c), cost + 1);

        add(a, b - min(C - c, b), c + min(C - c, b), cost + 1);
        add(a, b + min(B - b, c), c - min(B - b, c), cost + 1);
        
    }

    for(int k = 0; k <= C; k++)
        ans[k] = inf;

    for(auto p : vis) {
        ans[get<0>(p.first)] = min(ans[get<0>(p.first)], p.second);
        ans[get<1>(p.first)] = min(ans[get<1>(p.first)], p.second);
        ans[get<2>(p.first)] = min(ans[get<2>(p.first)], p.second);
    }

    ans[aa] = 0;
    ans[bb] = 0;
    ans[cc] = 0;

    for(int k = 0; k <= C; k++)
        cout << (ans[k] == inf ? -1 : ans[k]) << ' ';

    cout << '\n';
    
}