#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define st first
#define nd second
#define turbo ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define qi queue<int>
#define ld long double
using namespace std;
/*---------------------------------------------------------///CODE///---------------------------------------------------------*/
map<vector<pii>, bool> M;
const int N = 1e5;
vi T(N + 10, INT_MAX);
void go(vector<pii> v)
{
queue<pair<vector<pii>, int >> q;
q.push({v, 0});
while(!q.empty())
{
auto f = q.front();
q.pop();
if(M[f.st]) continue;
M[f.st] = true;
T[f.st[0].st] = min(T[f.st[0].st], f.nd);
T[f.st[1].st] = min(T[f.st[1].st], f.nd);
T[f.st[2].st] = min(T[f.st[2].st], f.nd);
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
if(i != j)
{
int help = min(f.st[j].nd, f.st[j].st + f.st[i].st);
int help2 = help - f.st[j].st;
auto temp = f.st;
temp[i].st -= help2;
temp[j].st = help;
q.push({temp, f.nd + 1});
}
}
}
int main()
{
turbo
int A, B, C, a, b, c; cin >> A >> B >> C >> a >> b >> c;
go({{a, A}, {b, B}, {c, C}});
for(int i = 0; i <= C; i++)
cout << (T[i] == INT_MAX ? -1 : T[i]) << " ";
return 0;
}
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 | #include<bits/stdc++.h> #define ll long long #define pii pair<int, int> #define st first #define nd second #define turbo ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define pb push_back #define vi vector<int> #define vvi vector<vi> #define qi queue<int> #define ld long double using namespace std; /*---------------------------------------------------------///CODE///---------------------------------------------------------*/ map<vector<pii>, bool> M; const int N = 1e5; vi T(N + 10, INT_MAX); void go(vector<pii> v) { queue<pair<vector<pii>, int >> q; q.push({v, 0}); while(!q.empty()) { auto f = q.front(); q.pop(); if(M[f.st]) continue; M[f.st] = true; T[f.st[0].st] = min(T[f.st[0].st], f.nd); T[f.st[1].st] = min(T[f.st[1].st], f.nd); T[f.st[2].st] = min(T[f.st[2].st], f.nd); for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) if(i != j) { int help = min(f.st[j].nd, f.st[j].st + f.st[i].st); int help2 = help - f.st[j].st; auto temp = f.st; temp[i].st -= help2; temp[j].st = help; q.push({temp, f.nd + 1}); } } } int main() { turbo int A, B, C, a, b, c; cin >> A >> B >> C >> a >> b >> c; go({{a, A}, {b, B}, {c, C}}); for(int i = 0; i <= C; i++) cout << (T[i] == INT_MAX ? -1 : T[i]) << " "; return 0; } |
English