Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int N = 1005;
- typedef pair<int, pair<int, int> > piii;
- int n, k;
- int z, s, m, z0, s0, m0;
- int change[N][6];
- queue<int> qx, qy, qz;
- map<piii, int> ma;
- vector<piii> res;
- void solve() {
- while(!qx.empty()) {
- int z = qx.front(); qx.pop();
- int s = qy.front(); qy.pop();
- int m = qz.front(); qz.pop();
- if(z >= z0 && s >= s0 && m >= m0) {
- res.push_back(make_pair(z, make_pair(s, m)));
- continue;
- }
- int step = ma[make_pair(z, make_pair(s, m))];
- if(step >= k) continue;
- for(int i = 1; i <= n; ++i) {
- if(z >= change[i][1] && s >= change[i][2] && m >= change[i][3]) {
- int nz = z - change[i][1] + change[i][4];
- int ns = s - change[i][2] + change[i][5];
- int nm = m - change[i][3] + change[i][6];
- if(nz > 4 || ns > 4 || nm > 4) continue;
- piii state = make_pair(nz, make_pair(ns, nm));
- if(!ma.count(state)) {
- ma[state] = step + 1;
- qx.push(nz);
- qy.push(ns);
- qz.push(nm);
- }
- }
- }
- }
- if(res.size() == 0)
- cout << -1 << '\n';
- else {
- sort( res.begin(), res.end());
- cout << res.size() << '\n';
- for(auto x : res)
- cout << x.first << ' ' << x.second.first << ' ' << x.second.second << ' ' << ma[x] << '\n';
- }
- }
- int main() {
- //#ifdef LOCAL
- // freopen("in.txt", "r", stdin);
- //#else
- // freopen("COLLECT.inp", "r", stdin);
- // freopen("COLLECT.out", "w", stdout);
- //#endif
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cin >> k;
- cin >> z >> s >> m >> z0 >> s0 >> m0;
- n = 1;
- while(cin >> change[n][1] >> change[n][2] >> change[n][3] >> change[n][4] >> change[n][5] >> change[n][6])
- ++n;
- qx.push(z);
- qy.push(s);
- qz.push(m);
- ma[make_pair(z, make_pair(s, m))] = 0;
- solve();
- return 0;
- }
Add Comment
Please, Sign In to add comment