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

using namespace std;
vector<int> V(3);
vector<int> curr(3);
int A,B,C, a, b, c;
int currtime;
struct state
{
    int a, b, c;
    int time=0;
};
void Przelej(int x, int y, int z, vector<vector<int>> &Empty, vector<vector<int>> &Full, queue<state> &Q)
{
    state t;
    vector<int> vec(3);
    if(curr[x]+curr[y]<=V[y])
    {
        vec[x]=0;
        vec[y]=curr[x]+curr[y];
        vec[z]=curr[z];
        t.time=currtime+1;
        t.a=vec[0];
        t.b=vec[1];
        t.c=vec[2];
        if(Empty[x][vec[(x+1)%3]]==-1)
            Q.push(t);
        return;
    }else{
        vec[x]=(curr[x]-(V[y]-curr[y]));
        vec[y]=V[y];
        vec[z]=curr[z];
        t.time=currtime+1;
        t.a=vec[0];
        t.b=vec[1];
        t.c=vec[2];
        if(Full[y][vec[(y+1)%3]]==-1)
            Q.push(t);
        return;
    }
}
int main()
{
    cin >> V[0] >> V[1] >> V[2] >> curr[0] >> curr[1] >> curr[2];
    queue<state> Q;
    state temp;
    temp.a=curr[0];
    temp.b=curr[1];
    temp.c=curr[2];
    temp.time=0;
    A=V[0];
    B=V[1];
    C=V[2];
    vector<int> time(C+1, -1);
    vector<vector<int>> Empty(3, vector<int> (C+1, -1));
    vector<vector<int>> Full(3, vector<int> (C+1, -1));
    Q.push(temp);
    while(!Q.empty())
    {
        a=Q.front().a;
        b=Q.front().b;
        c=Q.front().c;
        curr[0]=a;
        curr[1]=b;
        curr[2]=c;
        currtime=Q.front().time;
        Q.pop();
        if(time[a]==-1)
            time[a]=currtime;
        if(time[b]==-1)
            time[b]=currtime;
        if(time[c]==-1)
            time[c]=currtime;
        if(a==A)
            Full[0][b]=currtime;
        if(b==B)
            Full[1][c]=currtime;
        if(c==C)
            Full[2][a]=currtime;
        if(a==0)
            Empty[0][b]=currtime;
        if(b==0)
            Empty[1][c]=currtime;
        if(c==0)
            Empty[2][a]=currtime;
        Przelej(0, 1, 2, Empty, Full, Q);
        Przelej(1, 0, 2, Empty, Full, Q);
        Przelej(0, 2, 1, Empty, Full, Q);
        Przelej(2, 0, 1, Empty, Full, Q);
        Przelej(1, 2, 0, Empty, Full, Q);
        Przelej(2, 1, 0, Empty, Full, Q);
    }
    for(int i=0; i<=C; i++)
        cout << time[i] << ' ';
    return 0;
}