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
#include <iostream>
#include <set>
#include <queue>
using namespace std;

queue<pair<pair<int,int>,pair<int,int>>> s;
set<pair<pair<int,int>, int>> vis;
int A, B, C, a, b, c;
int t[100005], R[3];

int main(){
	cin >> A >> B >> C;
	for (int i = 0; i <= C; i++){
		t[i] = 1000005;
	}
	R[0] = A;
	R[1] = B;
	R[2] = C;
	cin >> a >> b >> c;
	s.push(make_pair(make_pair(a, b), make_pair(c, 0)));
	vis.insert(make_pair(make_pair(a, b), c));
	while (!s.empty()){
		pair<pair<int,int>,pair<int,int>> f = s.front();
		s.pop();
		int r[3] = {f.first.first, f.first.second, f.second.first};
		for (int i = 0; i < 3; i++){
			t[r[i]] = min(t[r[i]], f.second.second);
		}
		for (int i = 0; i < 3; i++){
			for (int j = 0; j < 3; j++){
				if (i != j){
					int fij = min(r[i], R[j] - r[j]);
					r[i] -= fij;
					r[j] += fij;
					if (vis.find(make_pair(make_pair(r[0], r[1]), r[2])) == vis.end()){
						vis.insert(make_pair(make_pair(r[0], r[1]), r[2]));
						s.push(make_pair(make_pair(r[0], r[1]), make_pair(r[2], f.second.second + 1)));
					}
					r[i] += fij;
					r[j] -= fij;
				}
			}
		}
	}
	for (int i = 0; i < C + 1; i++){
		if (t[i] > 1000000){
			cout << "-1 ";
		}
		else {
			cout << t[i] << " ";
		}
	}
}