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

struct xx
{
    int a[3];
    void inti(int A, int B, int C)
    {
        a[0] = A;
        a[1] = B;
        a[2] = C;
    }
    bool operator<(const xx o) const
    {
        if (a[0] != o.a[0])
            return a[0] < o.a[0];
        if (a[1] != o.a[1])
            return a[1] < o.a[1];
        return a[2] < o.a[2];
    }
};

int w[100005];

map<xx, bool> f;

int main()
{
    ios_base::sync_with_stdio(0);
    int A[3], B, C, a, b, c;
    cin >> A[0] >> A[1] >> A[2] >> a >> b >> c;
    for (int i = 0; i <= A[2]; i++)
        w[i] = -1;
    xx tf;
    tf.inti(a, b, c);
    queue<pair<xx, int>> q;
    f[tf] = 1;
    q.push({tf, 0});
    while (q.size())
    {
        xx t1 = q.front().first;
        int ks = q.front().second;
        q.pop();
        for (int i = 0; i < 3; i++)
        {
            if (w[t1.a[i]] == -1)
                w[t1.a[i]] = ks;
            for (int j = 0; j < 3; j++)
            {
                if (i == j)
                    continue;
                tf = t1;
                int n1 = min(tf.a[i] + tf.a[j], A[i]);
                tf.a[j] -= n1 - tf.a[i];
                tf.a[i] = n1;
                if(f[tf]==0){
                    f[tf]=1;
                    q.push({tf,ks+1});
                }
            }
        }
    }
    for (int i = 0; i <= A[2]; i++)
        cout<<w[i]<<' ';
}