Guest User

aoc 2025 10 p1

a guest
Dec 10th, 2025
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. #include <unordered_map>
  6. #include <unordered_set>
  7. #include <queue>
  8. #include <cmath>
  9. using namespace std;
  10.  
  11. #define ll long long
  12.  
  13. std::vector<string> split(std::string s, std::string&& delim) {
  14. std::vector<string> tokens;
  15. int start = 0;
  16. int end;
  17. while( (end = s.find(delim, start)) != string::npos) {
  18. tokens.push_back(s.substr(start, end - start));
  19. start = end + delim.length();
  20. }
  21. if(start < s.length()) {
  22. tokens.push_back(s.substr(start));
  23. }
  24. return tokens;
  25. }
  26.  
  27. ll solveSingle(int curr, std::vector<std::vector<int>>& buttons, std::vector<ll>& dp, int target) {
  28. if(dp[curr] >= 0) {
  29. return dp[curr];
  30. }
  31. if(dp[curr] == -1) {
  32. return -1;
  33. }
  34. dp[curr] = -1;
  35. if(curr == target) {
  36. dp[curr] = 0;
  37. return dp[curr];
  38. }
  39. ll total = LLONG_MAX;
  40. for(const auto& button : buttons) {
  41. int nextState = curr;
  42. vector<int> boof = {0,1};
  43. for(const auto & b : button) {
  44. nextState ^= (1 << b);
  45. }
  46. ll val = solveSingle(nextState, buttons, dp, target);
  47. if(val >= 0 && val != LLONG_MAX) {
  48. total = std::min(total, 1 + val);
  49. }
  50. }
  51. dp[curr] = total;
  52. return dp[curr];
  53. }
  54.  
  55. ll solve(std::vector<std::vector<std::vector<int>>>& buttons, std::vector<int>& targets, std::vector<int>& maxes) {
  56. ll ans = 0;
  57. for(int i=0;i<buttons.size(); i++) {
  58. std::vector<ll> dp(maxes[i], -2);
  59. ans += solveSingle(0, buttons[i], dp, targets[i]);
  60. }
  61. return ans;
  62. }
  63.  
  64. ll solve2(std::vector<std::vector<std::vector<int>>>& buttons, std::vector<int>& targets, std::vector<std::vector<int>>& joltages) {
  65. ll ans = 0;
  66. // Imma use python cause I'm lazy
  67. return ans;
  68. }
  69.  
  70. int main() {
  71. ifstream inputFile("../data/day10.txt");
  72. std::string line;
  73. std::vector<std::vector<std::vector<int>>> buttons;
  74. std::vector<int> targets;
  75. std::vector<int> maxes;
  76. std::vector<std::vector<int>> joltages;
  77. while(std::getline(inputFile, line)) {
  78. vector<string> inputs = split(line, " ");
  79. int target = 0;
  80. int max = 0;
  81. std::string strTarget = inputs[0].substr(1,inputs[0].length()-2);
  82.  
  83. for(int i=0; i<strTarget.length(); i++) {
  84. if(strTarget[i] == '#') {
  85. target += (1 << i);
  86. }
  87. max += (1<<i);
  88. }
  89. targets.push_back(target);
  90. maxes.push_back(max+1);
  91. vector<vector<int>> buttonList;
  92. for(int i=1; i<inputs.size()-1;i++) {
  93. auto buttonStr = split(inputs[i].substr(1,inputs[i].length()-2), ",");
  94. vector<int> button;
  95. for(const auto&s : buttonStr) {
  96. button.push_back(std::stoi(s));
  97. }
  98. buttonList.push_back(button);
  99. }
  100. buttons.push_back(buttonList);
  101. vector<int> joltage;
  102. auto joltageStr = split(inputs.back().substr(1,inputs.back().length()-2), ",");
  103. for(const auto&s : joltageStr) {
  104. joltage.push_back(std::stoi(s));
  105. }
  106. joltages.push_back(joltage);
  107.  
  108. }
  109. std::cout << solve(buttons, targets, maxes) << std::endl;
  110. return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment