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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <bits/stdc++.h>

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int ASize, BSize, CSize;
    cin >> ASize >> BSize >> CSize;
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> answers(CSize + 1, -1);
    answers[a] = 0;
    answers[b] = 0;
    answers[c] = 0;
    queue<vector<int>> que;
    que.push({a, b, c, 0});
    set<vector<int>> visitedSet;
    visitedSet.insert({a, b, c});
    int added = 1;
    while (!que.empty()) {
        vector<int> toDo = que.front();
        que.pop();
        int x = toDo[0], y = toDo[1], z = toDo[2], iter = toDo[3] + 1;
        if (x != ASize) {
            if (x + y <= ASize) {
                if (visitedSet.find({x + y, 0, z}) == visitedSet.end()) { 
                    que.push({x + y, 0, z, iter});
                    visitedSet.insert({x + y, 0, z});
                }
                if (answers[x + y] < 0) 
                    answers[x + y] = iter;
                if (answers[0] < 0) 
                    answers[0] = iter;
            } else {
                if (x + y - ASize <= CSize && answers[x + y - ASize] < 0) 
                    answers[x + y - ASize] = iter;
                if (answers[ASize] < 0) 
                    answers[ASize] = iter;
                if (visitedSet.find({ASize, x + y - ASize, z}) == visitedSet.end()) {
                    que.push({ASize, x + y - ASize, z, iter});
                    visitedSet.insert({ASize, x + y - ASize, z});
                }
            }
            if (x + z <= ASize) {
                if (visitedSet.find({x + z, y, 0}) == visitedSet.end()) {
                    que.push({x + z, y, 0, iter});
                    visitedSet.insert({x + z, y, 0});
                }
                if (answers[x + z] < 0) 
                    answers[x + z] = iter;
                if (answers[0] < 0) 
                    answers[0] = iter;
            } else {
                if (x + z - ASize <= CSize && answers[x + z - ASize] < 0) 
                    answers[x + z - ASize] = iter;
                if (answers[ASize] < 0) 
                    answers[ASize] = iter;
                if (visitedSet.find({ASize, y, x + z - ASize}) == visitedSet.end()) {
                    que.push({ASize, y, x + z - ASize, iter});
                    visitedSet.insert({ASize, y, x + z - ASize});
                }
            }
        }
        if (y != BSize) {
            if (x + y <= BSize) {
                if (visitedSet.find({0, x + y, z}) == visitedSet.end()) {
                    que.push({0, x + y, z, iter});
                    visitedSet.insert({0, x + y, z});
                }
                if (answers[x + y] < 0) 
                    answers[x + y] = iter;
                if (answers[0] < 0) 
                    answers[0] = iter;
            } else {
                if (x + y - BSize <= CSize && answers[x + y - BSize] < 0) 
                    answers[x + y - BSize] = iter;
                if (answers[BSize] < 0) 
                    answers[BSize] = iter;
                if (visitedSet.find({x + y - BSize, BSize, z}) == visitedSet.end()) {
                    que.push({x + y - BSize, BSize, z, iter});
                    visitedSet.insert({x + y - BSize, BSize, z});
                }
            }
            if (y + z <= BSize) {
                if (visitedSet.find({x, y + z, 0}) == visitedSet.end()) {
                    que.push({x, y + z, 0, iter});
                    visitedSet.insert({x, y + z, 0});
                }
                if (answers[y + z] < 0) 
                    answers[y + z] = iter;
                if (answers[0] < 0) 
                    answers[0] = iter;
            } else {
                if (y + z - BSize <= CSize && answers[y + z - BSize] < 0) 
                    answers[y + z - BSize] = iter;
                if (answers[BSize] < 0) 
                    answers[BSize] = iter;
                if (visitedSet.find({x, BSize, y + z - BSize}) == visitedSet.end()) {
                    que.push({x, BSize, y + z - BSize, iter});
                    visitedSet.insert({x, BSize, y + z - BSize});
                }
            }
        }
        if (z != CSize) {
            if (x + z <= CSize) {
                if (visitedSet.find({0, y, x + z}) == visitedSet.end()) {
                    que.push({0, y, x + z, iter});
                    visitedSet.insert({0, y, x + z});
                }
                if (answers[x + z] < 0) 
                    answers[x + z] = iter;
                if (answers[0] < 0) 
                    answers[0] = iter;
            } else {
                if (x + z - CSize <= CSize && answers[x + z - CSize] < 0) 
                    answers[x + z - CSize] = iter;
                if (answers[CSize] < 0) 
                    answers[CSize] = iter;
                if (visitedSet.find({x + z - CSize, y, CSize}) == visitedSet.end()) {
                    que.push({x + z - CSize, y, CSize, iter});
                    visitedSet.insert({x + z - CSize, y, CSize});
                }
            }
            if (y + z <= CSize) {
                if (visitedSet.find({x, 0, y + z}) == visitedSet.end()) {
                    que.push({x, 0, y + z, iter});
                    visitedSet.insert({x, 0, y + z});
                }
                if (answers[y + z] < 0) 
                    answers[y + z] = iter;
                if (answers[0] < 0) 
                    answers[0] = iter;
            } else {
                if (y + z - CSize <= CSize && answers[y + z - CSize] < 0) 
                    answers[y + z - CSize] = iter;
                if (answers[CSize] < 0) 
                    answers[CSize] = iter;
                if (visitedSet.find({x, y + z - CSize, CSize}) == visitedSet.end()) {
                    que.push({x, y + z - CSize, CSize, iter});
                    visitedSet.insert({x, y + z - CSize, CSize});
                }
            }
        }
    }
    for (auto &x : answers) {
            cout << x << " "; 
        }
        cout << endl;
    return 0;
}