The following code
struct Solution final {
struct pair_hash final {
auto constexpr
operator()(std::pair<int, int> const p) const noexcept -> std::size_t {
static_assert(sizeof(int) + sizeof(int) == sizeof(std::size_t),
"Needs to work for hack");
return (static_cast<std::size_t>(p.first) << 32) |
static_cast<size_t>(p.second);
}
};
std::unordered_map<std::pair<int, int>, int, pair_hash> memo = {};
std::span<int> cs;
auto impl(int x, int i) noexcept -> int {
if (memo.find(std::make_pair(x, i)) != memo.end())
return memo.at(std::make_pair(x, i));
if (i == static_cast<int>(cs.size()))
return x == 0 ? 1 : 0;
auto const take = (cs[static_cast<size_t>(i)] <= x)
? impl(x - cs[static_cast<size_t>(i)], i)
: 0;
auto const skip = impl(x, i + 1);
memo[std::make_pair(x, i)] = take + skip;
return take + skip;
}
int change(int amount, std::vector<int> &coins) {
cs = coins;
return impl(amount, 0);
}
};
Works as a solution to 518 Coin Change II.
However when run locally (clang version 18.1.6 (Fedora 18.1.6-3.fc40), or with g++ version 14.2.1 20240801 (Red Hat 14.2.1-1), they both fail) some of the cases fail, while others succeed.
I found here that leetcode uses clang 17 for c++.
This is a different version from what I was locally compiling the program with, but I don’t see how that would change the semantics of the resulting binary.
What I’m wondering is where would I submit a bug report, is this a compiler regression on clang’s end, or an issue with the Fedora’s repos?
Izik P. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.