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

typedef long long int LL;

const int MAX_N = 1000005;

int A, B, C;
int a, b, c;

map<vector<int>, int> counts;
unordered_map<int, int> results;

vector<int> sizes(3), currents(3);

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

    cin >> sizes[0] >> sizes[1] >> sizes[2];
    cin >> currents[0] >> currents[1] >> currents[2];

    counts[currents] = 0;
    for(int i = 0; i < 3; ++i)
    {
        results[currents[i]] = 0;
    }

    queue<vector<int>> q;
    q.push(currents);

    while(!q.empty())
    {
        vector<int> u = q.front();
        q.pop();

        for(int i = 0; i < 3; ++i)
        {
            for(int j = 0; j < 3; ++j)
            {
                if(i == j)
                {
                    continue;
                }

                vector<int> v = u;
                const int toTransfer = min(u[i], sizes[j]-u[j]);
                v[i] -= toTransfer;
                v[j] += toTransfer;

                if(counts.find(v) != counts.cend())
                {
                    continue;
                }

                q.push(v);
                counts[v] = counts[u]+1;
                for(int k = 0; k < 3; ++k)
                {
                    if(results.find(v[k]) == results.cend())
                    {
                        results[v[k]] = counts[v];
                    }
                }
            }
        }
    }

    for(int i = 0; i <= sizes[2]; ++i)
    {
        const auto it = results.find(i);
        cout << (it == results.cend() ? -1 : it->second) << ' ';
    }
    cout << endl;

    return 0;
}