GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 16 / 0 / 16
Functions: 100.0% 3 / 0 / 3
Branches: 90.0% 9 / 0 / 10

src/opt/larsch/d1/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 template <arithm_c T, class Func>
9 requires requires(Func f, u32 x, u32 y) { {f(x,y)}->std::same_as<T>; }
10 49 CEXP vec<T> larsch(u32 n, Func&& w, T inf = inf_v<T>) NE {
11 98 vec<T> dp(n + 1, inf);
12 49 vecu x(n + 1);
13 35718591 auto chk = [&](u32 from, u32 to) {
14
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35718542 times.
35718542 if (from >= to) return;
15
2/2
✓ Branch 3 taken 1586813 times.
✓ Branch 4 taken 34131729 times.
35718542 if (T cost = w(from, to); dp[from] + cost < dp[to]) dp[to] = dp[from] + cost, x[to] = from;
16 };
17 4269736 auto f = [&](auto&& f, u32 l, u32 r) -> void {
18
2/2
✓ Branch 0 taken 2134868 times.
✓ Branch 1 taken 2134819 times.
4269687 if (l + 1 >= r) return;
19 2134819 u32 m = l + (r - l) / 2;
20
2/2
✓ Branch 3 taken 17810418 times.
✓ Branch 4 taken 2134819 times.
19945237 for (u32 i = x[l]; i <= x[r]; i++) chk(i, m);
21 2134819 f(f, l, m);
22
2/2
✓ Branch 1 taken 17908075 times.
✓ Branch 2 taken 2134819 times.
20042894 for (u32 i = l + 1; i <= m; i++) chk(i, r);
23 2134819 f(f, m, r);
24 };
25 49 dp[0] = 0, chk(0, n), f(f, 0, n);
26 49 return dp;
27 49 };
28
29 } // namespace tifa_libs
30