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

using namespace std;

const int MAXN = 1e5 + 7;

set<vector<int>> seen;
vector<int> need_moves(MAXN, MAXN);

int A, B, C;
void rec(int a, int b, int c, int moves){
    seen.insert({a, b, c});
    need_moves[a] = min(need_moves[a], moves);
    need_moves[b] = min(need_moves[b], moves);
    need_moves[c] = min(need_moves[c], moves);

    //z a do b
    if (seen.count({max(0, a - (B-b)), min(B, b+a), c}) == false)
        rec(max(0, a - (B-b)), min(B, a+b), c, moves+1);
    
    //z a do c
    if (seen.count({max(0, a - (C-c)), b, min(C, a+c)}) == false)
        rec(max(0, a - (C-c)), b, min(C, a+c), moves+1);
    
    //z b do a
    if (seen.count({min(A, a+b), max(0, b - (A-a)), c}) == false)
        rec(min(A, a+b), max(0, b - (A-a)), c, moves+1);
    
    //z b do c
    if (seen.count({a, max(0, b - (C-c)), min(C, c+b)}) == false)
        rec(a, max(0, b - (C-c)), min(C, c+b), moves+1);
    
    //z c do a
    if (seen.count({min(A, a+c), b, max(0, c - (A-a))}) == false)
        rec(min(A, a+c), b, max(0, c - (A-a)), moves+1);
    
    //z c do b
    if (seen.count({a, min(B, b+c), max(0, c - (B-b))}) == false)
        rec(a, min(B, b+c), max(0, c - (B-b)), moves+1);
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int a, b, c;
    cin >> A >> B >> C;
    cin >> a >> b >> c;

    vector<vector<int>> que, que_now;
    que.push_back({a, b, c});
    
    for (int m = 0; que.size() > 0; m++){
        for (auto& v : que){
            a = v[0], b = v[1], c = v[2];
            need_moves[a] = min(need_moves[a], m);
            need_moves[b] = min(need_moves[b], m);
            need_moves[c] = min(need_moves[c], m);

            //z a do b
            if (seen.count({max(0, a - (B-b)), min(B, b+a), c}) == false){
                que_now.push_back({max(0, a - (B-b)), min(B, b+a), c});
                seen.insert({max(0, a - (B-b)), min(B, b+a), c});
            }
            //z a do c
            if (seen.count({max(0, a - (C-c)), b, min(C, a+c)}) == false){
                que_now.push_back({max(0, a - (C-c)), b, min(C, a+c)});
                seen.insert({max(0, a - (C-c)), b, min(C, a+c)});
            }
            //z b do a
            if (seen.count({min(A, a+b), max(0, b - (A-a)), c}) == false){
                que_now.push_back({min(A, a+b), max(0, b - (A-a)), c});   
                seen.insert({min(A, a+b), max(0, b - (A-a)), c});
            }         
            //z b do c
            if (seen.count({a, max(0, b - (C-c)), min(C, c+b)}) == false){
                que_now.push_back({a, max(0, b - (C-c)), min(C, c+b)});   
                seen.insert({a, max(0, b - (C-c)), min(C, c+b)});
            }         
            //z c do a
            if (seen.count({min(A, a+c), b, max(0, c - (A-a))}) == false){
                que_now.push_back({min(A, a+c), b, max(0, c - (A-a))});   
                seen.insert({min(A, a+c), b, max(0, c - (A-a))});
            }         
            //z c do b
            if (seen.count({a, min(B, b+c), max(0, c - (B-b))}) == false){
                que_now.push_back({a, min(B, b+c), max(0, c - (B-b))});
                seen.insert({a, min(B, b+c), max(0, c - (B-b))});
            }
        }
        que = que_now;
        que_now.clear();
    }

    for (int i = 0; i <= C; i++)
        cout << ((need_moves[i] == MAXN) ? -1 : need_moves[i]) << " ";

    return 0;
}

/*
2 7 9
1 3 6
*/