GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 24 / 0 / 24
Functions: 100.0% 3 / 0 / 3
Branches: 92.9% 13 / 0 / 14

src/opt/knapsack/mixed_huge/lib.hpp
Line Branch Exec Source
1 #pragma once
2
3 #include "../../../util/alias/others/lib.hpp"
4 #include "../../../util/traits/math/lib.hpp"
5
6 namespace tifa_libs {
7
8 //@param a a[i]={value, weight, count}
9 //@param W max weight
10 //@return max total value while total weight <= W
11 template <int_c T>
12 60 CEXP T knapsack_mixed_huge(vec<pt3<T>> a, T W) NE {
13 60 cu32 n = (u32)a.size();
14
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
60 assert(n < 500);
15 120 cu32 lim = [k = max(n, 50_u32)] { return k * k * k + 1; }();
16 60 vec<T> dp(lim + 1, to_uint_t<T>(-1) / 2 - 1);
17 60 dp[0] = 0;
18
2/2
✓ Branch 5 taken 1525 times.
✓ Branch 6 taken 60 times.
1585 for (auto& [v, w, num] : a) {
19 1525 T have = min(num, (T)n);
20 1525 num -= have;
21
2/2
✓ Branch 1 taken 8402 times.
✓ Branch 2 taken 1525 times.
9927 for (T k = 1; k = min(have, k), have; have -= k, k <<= 1)
22
2/2
✓ Branch 4 taken 1048747920 times.
✓ Branch 5 taken 8402 times.
1048756322 for (u32 j = lim - 1; (T)j >= v * k; --j) dp[j] = min(dp[j], dp[j - v * k] + w * k);
23 }
24 60 vecu id(n);
25 9178 std::iota(begin(id), end(id), 0), sort(id, [&](auto x, auto y) { return a[x]._0 * a[y]._1 > a[y]._0 * a[x]._1; });
26 60 T ans = 0;
27
2/2
✓ Branch 0 taken 7500120 times.
✓ Branch 1 taken 60 times.
7500180 flt_ (u32, j, 0, lim + 1) {
28
2/2
✓ Branch 1 taken 7467069 times.
✓ Branch 2 taken 33051 times.
7500120 if (W < dp[j]) continue;
29 33051 T rest = W - dp[j], now = j;
30
2/2
✓ Branch 4 taken 1232672 times.
✓ Branch 5 taken 33051 times.
1265723 for (auto i : id) {
31 1232672 auto [v, w, num] = a[i];
32 1232672 T div = min(num, rest / w);
33 1232672 rest -= div * w, now += div * v;
34 }
35 33051 ans = max(ans, now);
36 }
37 120 return ans;
38 60 }
39
40 } // namespace tifa_libs
41