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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int INF = 1000000009;

int volume[3];
vector<int> init_state(3);
int res[100009];
unordered_set<ll> vis;

inline ll hash_state(const vector<int>& state) {
    return state[0] + 1e6*(ll)state[1] + 1e12*(ll)state[2];
}

inline void update(const vector<int>& state, int x) {
    for(auto a : state)
        res[a] = min(res[a], x);
}

vector<int> move(int a, int b, vector<int> state) {
    int tmp = volume[b] - state[b];
    if(tmp < state[a]){
        state[b] = volume[b];
        state[a] -= tmp;
    }
    else {
        state[b] += state[a];
        state[a] = 0;
    }
    return state;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> volume[0] >> volume[1] >> volume[2];
    cin >> init_state[0] >> init_state[1] >> init_state[2];

    fill(res, res+100005, INF);

    queue<pair<vector<int>,int> > q;
    q.push({init_state, 0});
    while(not q.empty()) {
        vector<int> state = q.front().first;
        int x = q.front().second;
        q.pop();

        update(state, x);
        for(int a = 0; a < 3; a++) {
            for(int b = 0; b < 3; b++) {
                if(a == b)
                    continue;
                vector<int> newstate = move(a,b,state);
                update(newstate, x+1);
                ll h = hash_state(newstate);
                if(vis.find(h) == vis.end()) {
                    vis.insert(h);
                    q.push({newstate, x+1});
                }
            }
        }
    }

    for(int i = 0; i <= volume[2]; i++)
        cout << (res[i] == INF ? -1 : res[i]) << " ";
    cout << "\n";

    return 0;
}