leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE |

commit7afe9d85ae8503e3a6ff01329325693512cd15f0
parent0139196197967243a515de3c3eb7eb89d8dd09d1
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateTue, 25 Jun 2024 11:34:57 +0200

1 Random Problem

Diffstat:
AProblems/2212.cpp|+++++++++++++++++++++++++++++
MREADME.md|+

2 files changed, 30 insertions(+), 0 deletions(-)


diff --git a/Problems/2212.cpp b/Problems/2212.cpp

@@ -0,0 +1,29 @@

class Solution {
public:
vector<int> maximumBobPoints(const int numArrows, const vector<int> &aliceArrows) const {
vector<int> res;
int maxi = 0;
for (int i = 0; i < (1 << 11); i++) {
unsigned mask = i, score = 0, total = 0;
static int crnt[12];
memset(crnt, 0x00, sizeof(crnt));
while (mask) {
int idx = std::countr_zero(mask);
mask ^= 1u << idx++;
total += crnt[idx] = aliceArrows[idx] + 1;
score += idx;
}
if (total <= numArrows && score > maxi) {
res = vector<int>(crnt, crnt + 12);
res[0] += numArrows - total;
maxi = score;
}
}
return res;
}
};

diff --git a/README.md b/README.md

@@ -1080,6 +1080,7 @@ for solving problems.

| 2192 | Medium | [All Ancestors of a Node in a Directed Acyclic Graph](Problems/2192.cpp) |
| 2196 | Medium | [Create Binary Tree From Descriptions](Problems/2196.cpp) |
| 2201 | Medium | [Count Artifacts That Can Be Extracted](Problems/2201.cpp) |
| 2212 | Medium | [Maximum Points in an Archery Competition](Problems/2212.cpp) |
| 2215 | Easy | [Find the Difference of Two Arrays](Problems/2215.cpp) |
| 2218 | Hard | [Maximum Value of K Coins From Piles](Problems/2218.cpp) |
| 2221 | Medium | [Find Triangular Sum of an Array](Problems/2221.cpp) |