Advertisement
Guest User

Untitled

a guest
Dec 19th, 2022
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.91 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <cassert>
  4. #include <limits>
  5. #include <map>
  6. #include <string>
  7. #include <set>
  8. #include <queue>
  9. #include <unordered_set>
  10. #include <algorithm>
  11. #include <random>
  12. #include <unordered_map>
  13. #include <sstream>
  14. #include <numeric>
  15. #include <stack>
  16. #include <fstream>
  17.  
  18. struct Blueprint
  19. {
  20.     Blueprint()
  21.     {
  22.         for (int i = 0; i < 4; i++)
  23.             for (int j = 0; j < 4; j++)
  24.                 bots[i][j] = 0;
  25.     }
  26.  
  27.     int bots[4][4];
  28. };
  29.  
  30. int main()
  31. {
  32.     std::vector<std::string> resources = { "ore","clay","obsidian", "geode" };
  33.     std::vector<Blueprint> blueprints;
  34.     while (true)
  35.     {
  36.         std::string l;
  37.         std::getline(std::cin, l);
  38.         if (!std::cin)
  39.             break;
  40.         std::string dummy;
  41.         std::stringstream ss(l);
  42.         ss >> dummy >> dummy;
  43.         Blueprint bp;
  44.         for (int bot = 0; bot < 4; bot++)
  45.         {
  46.             ss >> dummy >> dummy >> dummy >> dummy;
  47.             bool done = false;
  48.            
  49.             while (!done)
  50.             {
  51.                 int cost;
  52.                 ss >> cost;
  53.                 std::string ore;
  54.                 ss >> ore;
  55.                 if (ore[ore.length() - 1] == '.')
  56.                 {
  57.                     ore.pop_back();
  58.                     done = true;
  59.                 }
  60.                 else
  61.                 {
  62.                     ss >> dummy;
  63.                 }
  64.                 for (int i = 0; i < 4; i++)
  65.                 {
  66.                     if (resources[i] == ore)
  67.                     {
  68.                         bp.bots[bot][i] += cost;
  69.                     }
  70.                 }
  71.                
  72.             }
  73.         }
  74.         blueprints.push_back(bp);
  75.     }
  76.  
  77.     int nbp = blueprints.size();
  78.  
  79.     struct State
  80.     {
  81.         int64_t ores[4];
  82.         int64_t bots[4];
  83.         int waitmask = 15;
  84.         int time;
  85.     };
  86.  
  87.     int64_t answer = 1;
  88.  
  89.     for (int bp = 0; bp < nbp; bp++)
  90.     {
  91.         State start;
  92.         for (int i = 0; i < 4; i++)
  93.         {
  94.             start.ores[i] = 0;
  95.             start.bots[i] = 0;
  96.         }
  97.         start.time = 0;
  98.         start.bots[0] = 1;
  99.  
  100.         std::deque<State> q;
  101.         q.push_back(start);
  102.         int64_t bestgeode = 0;
  103.         while (!q.empty())
  104.         {
  105.             auto next = q.front();
  106.             q.pop_front();
  107.  
  108.             if (next.time++ == 32)
  109.             {
  110.                 bestgeode = std::max(bestgeode, next.ores[3]);
  111.                 continue;
  112.             }
  113.  
  114.             for (int bot = 0; bot < 4; bot++)
  115.             {
  116.                 bool canbuy = (bot==3);
  117.                 for (int i = 0; i < 4; i++)
  118.                 {
  119.                     if (blueprints[bp].bots[i][bot] > next.bots[bot])
  120.                         canbuy = true;
  121.                 }
  122.                 canbuy = canbuy && (next.waitmask & (1LL << bot));
  123.                 for (int i = 0; i < 4; i++)
  124.                 {
  125.                     if (next.ores[i] < blueprints[bp].bots[bot][i])
  126.                         canbuy = false;
  127.                 }
  128.                 if (canbuy)
  129.                 {
  130.                     State news = next;
  131.                     for (int i = 0; i < 4; i++)
  132.                     {
  133.                         news.ores[i] -= blueprints[bp].bots[bot][i];
  134.  
  135.                         news.ores[i] += news.bots[i];
  136.                     }
  137.                     news.bots[bot]++;
  138.                     news.waitmask = 15;
  139.                     next.waitmask &= ~(1LL << bot);
  140.                     q.push_front(news);
  141.                 }
  142.             }
  143.             if (next.waitmask)
  144.             {
  145.                 for (int i = 0; i < 4; i++)
  146.                     next.ores[i] += next.bots[i];
  147.                 q.push_front(next);
  148.             }
  149.         }
  150.         std::cout << "Best is " << bestgeode << std::endl;
  151.         answer *= bestgeode;        
  152.     }
  153.     std::cout << answer << std::endl;
  154.    
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement