#include <algorithm>
#include <array>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
using LL = long long;
int main()
{
array<int, 3> ABC;
for (int i = 0; i < 3; ++i)
{
cin >> ABC[i];
}
vector<int> res(ABC[2] + 1, 10000000);
set<array<int, 3>> cur_set;
set<array<int, 3>> nxt_set;
set<array<int, 3>> all_set;
array<int, 3> cur;
for (int i = 0; i < 3; ++i)
{
cin >> cur[i];
}
cur_set.insert(cur);
all_set.insert(cur);
int r = 0;
while (cur_set.size())
{
for (const auto& elem : cur_set)
{
for (int i = 0; i < 3; ++i)
{
if (res[elem[i]] > r)
res[elem[i]] = r;
}
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
{
if (i == j)
continue;
array<int, 3> nxt;
for (int k = 0; k < 3; ++k)
{
nxt[k] = elem[k];
}
int x = min(elem[i], ABC[j] - elem[j]);
nxt[i] -= x;
nxt[j] += x;
if (all_set.find(nxt) == all_set.end())
{
nxt_set.insert(nxt);
all_set.insert(nxt);
}
}
}
}
cur_set = nxt_set;
nxt_set.clear();
++r;
}
for (int i = 0; i < ABC[2] + 1; ++i)
{
if (i)
cout << " ";
cout << (res[i] == 10000000 ? -1 : res[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 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 | #include <algorithm> #include <array> #include <iostream> #include <set> #include <vector> using namespace std; using LL = long long; int main() { array<int, 3> ABC; for (int i = 0; i < 3; ++i) { cin >> ABC[i]; } vector<int> res(ABC[2] + 1, 10000000); set<array<int, 3>> cur_set; set<array<int, 3>> nxt_set; set<array<int, 3>> all_set; array<int, 3> cur; for (int i = 0; i < 3; ++i) { cin >> cur[i]; } cur_set.insert(cur); all_set.insert(cur); int r = 0; while (cur_set.size()) { for (const auto& elem : cur_set) { for (int i = 0; i < 3; ++i) { if (res[elem[i]] > r) res[elem[i]] = r; } for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { if (i == j) continue; array<int, 3> nxt; for (int k = 0; k < 3; ++k) { nxt[k] = elem[k]; } int x = min(elem[i], ABC[j] - elem[j]); nxt[i] -= x; nxt[j] += x; if (all_set.find(nxt) == all_set.end()) { nxt_set.insert(nxt); all_set.insert(nxt); } } } } cur_set = nxt_set; nxt_set.clear(); ++r; } for (int i = 0; i < ABC[2] + 1; ++i) { if (i) cout << " "; cout << (res[i] == 10000000 ? -1 : res[i]); } return 0; } |
English