Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- #include <cassert>
- #include <limits>
- #include <map>
- #include <string>
- #include <set>
- #include <queue>
- #include <unordered_set>
- #include <algorithm>
- #include <random>
- #include <unordered_map>
- #include <sstream>
- #include <numeric>
- #include <stack>
- #include <fstream>
- struct Blueprint
- {
- Blueprint()
- {
- for (int i = 0; i < 4; i++)
- for (int j = 0; j < 4; j++)
- bots[i][j] = 0;
- }
- int bots[4][4];
- };
- int main()
- {
- std::vector<std::string> resources = { "ore","clay","obsidian", "geode" };
- std::vector<Blueprint> blueprints;
- while (true)
- {
- std::string l;
- std::getline(std::cin, l);
- if (!std::cin)
- break;
- std::string dummy;
- std::stringstream ss(l);
- ss >> dummy >> dummy;
- Blueprint bp;
- for (int bot = 0; bot < 4; bot++)
- {
- ss >> dummy >> dummy >> dummy >> dummy;
- bool done = false;
- while (!done)
- {
- int cost;
- ss >> cost;
- std::string ore;
- ss >> ore;
- if (ore[ore.length() - 1] == '.')
- {
- ore.pop_back();
- done = true;
- }
- else
- {
- ss >> dummy;
- }
- for (int i = 0; i < 4; i++)
- {
- if (resources[i] == ore)
- {
- bp.bots[bot][i] += cost;
- }
- }
- }
- }
- blueprints.push_back(bp);
- }
- int nbp = blueprints.size();
- struct State
- {
- int64_t ores[4];
- int64_t bots[4];
- int waitmask = 15;
- int time;
- };
- int64_t answer = 1;
- for (int bp = 0; bp < nbp; bp++)
- {
- State start;
- for (int i = 0; i < 4; i++)
- {
- start.ores[i] = 0;
- start.bots[i] = 0;
- }
- start.time = 0;
- start.bots[0] = 1;
- std::deque<State> q;
- q.push_back(start);
- int64_t bestgeode = 0;
- while (!q.empty())
- {
- auto next = q.front();
- q.pop_front();
- if (next.time++ == 32)
- {
- bestgeode = std::max(bestgeode, next.ores[3]);
- continue;
- }
- for (int bot = 0; bot < 4; bot++)
- {
- bool canbuy = (bot==3);
- for (int i = 0; i < 4; i++)
- {
- if (blueprints[bp].bots[i][bot] > next.bots[bot])
- canbuy = true;
- }
- canbuy = canbuy && (next.waitmask & (1LL << bot));
- for (int i = 0; i < 4; i++)
- {
- if (next.ores[i] < blueprints[bp].bots[bot][i])
- canbuy = false;
- }
- if (canbuy)
- {
- State news = next;
- for (int i = 0; i < 4; i++)
- {
- news.ores[i] -= blueprints[bp].bots[bot][i];
- news.ores[i] += news.bots[i];
- }
- news.bots[bot]++;
- news.waitmask = 15;
- next.waitmask &= ~(1LL << bot);
- q.push_front(news);
- }
- }
- if (next.waitmask)
- {
- for (int i = 0; i < 4; i++)
- next.ores[i] += next.bots[i];
- q.push_front(next);
- }
- }
- std::cout << "Best is " << bestgeode << std::endl;
- answer *= bestgeode;
- }
- std::cout << answer << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement