leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
2212.cpp (802B)
0 class Solution { 1 public: 2 vector<int> maximumBobPoints(const int numArrows, const vector<int> &aliceArrows) const { 3 vector<int> res; 4 int maxi = 0; 5 6 for (int i = 0; i < (1 << 11); i++) { 7 unsigned mask = i, score = 0, total = 0; 8 static int crnt[12]; 9 10 memset(crnt, 0x00, sizeof(crnt)); 11 while (mask) { 12 int idx = std::countr_zero(mask); 13 mask ^= 1u << idx++; 14 15 total += crnt[idx] = aliceArrows[idx] + 1; 16 score += idx; 17 } 18 19 if (total <= numArrows && score > maxi) { 20 res = vector<int>(crnt, crnt + 12); 21 res[0] += numArrows - total; 22 maxi = score; 23 } 24 } 25 26 return res; 27 } 28 };