This documentation is automatically generated by competitive-verifier/competitive-verifier
// competitive-verifier: PROBLEM https://yukicoder.me/problems/no/704
// competitive-verifier: TLE 0.5
// competitive-verifier: MLE 64
#include <iostream>
#include <algorithm>
#include "src/Optimization/simplified_larsch_dp.hpp"
using namespace std;
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
int n;
cin >> n;
long long a[n], x[n], y[n];
for (int i= 0; i < n; ++i) cin >> a[i];
for (int i= 0; i < n; ++i) cin >> x[i];
for (int i= 0; i < n; ++i) cin >> y[i];
auto f= [](long long x) { return abs(x); };
auto w= [&](int i, int j) { return f(x[j] - a[i - 1]) + f(y[j]); };
cout << simplified_larsch_dp(n, w)[n] << '\n';
return 0;
}
#line 1 "test/yukicoder/704.LARSCH.test.cpp"
// competitive-verifier: PROBLEM https://yukicoder.me/problems/no/704
// competitive-verifier: TLE 0.5
// competitive-verifier: MLE 64
#include <iostream>
#include <algorithm>
#line 2 "src/Optimization/simplified_larsch_dp.hpp"
#include <vector>
#include <limits>
#line 2 "src/Internal/function_traits.hpp"
#include <type_traits>
// clang-format off
namespace function_template_internal{
template<class C>struct is_function_object{
template<class U,int dummy=(&U::operator(),0)> static std::true_type check(U *);
static std::false_type check(...);
static C *m;
static constexpr bool value= decltype(check(m))::value;
};
template<class F,bool,bool>struct function_type_impl{using type= void;};
template<class F>struct function_type_impl<F,true,false>{using type= F *;};
template<class F>struct function_type_impl<F,false,true>{using type= decltype(&F::operator());};
template<class F> using function_type_t= typename function_type_impl<F,std::is_function_v<F>,is_function_object<F>::value>::type;
template<class... Args>struct result_type_impl{using type= void;};
template<class R,class... Args>struct result_type_impl<R(*)(Args...)>{using type= R;};
template<class C,class R,class... Args>struct result_type_impl<R(C::*)(Args...)>{using type= R;};
template<class C,class R,class... Args>struct result_type_impl<R(C::*)(Args...)const>{using type= R;};
template<class F> using result_type_t= typename result_type_impl<function_type_t<F>>::type;
template<class... Args>struct argument_type_impl{using type= void;};
template<class R,class... Args>struct argument_type_impl<R(*)(Args...)>{using type= std::tuple<Args...>;};
template<class C,class R,class... Args>struct argument_type_impl<R(C::*)(Args...)>{using type= std::tuple<Args...>;};
template<class C,class R,class... Args>struct argument_type_impl<R(C::*)(Args...)const>{using type= std::tuple<Args...>;};
template<class F> using argument_type_t= typename argument_type_impl<function_type_t<F>>::type;
}
using function_template_internal::result_type_t,function_template_internal::argument_type_t;
// clang-format on
#line 5 "src/Optimization/simplified_larsch_dp.hpp"
// dp[i] = min_{j<i} (dp[j] + w(i,j))
// w(i,j) -> monge cost
template <class F> std::vector<result_type_t<F>> simplified_larsch_dp(int n, const F &w) {
using T= result_type_t<F>;
std::vector<T> dp(n + 1, std::numeric_limits<T>::max());
std::vector<int> x(n + 1);
auto check= [&](int i, int j) {
if (T cost= dp[j] + w(i, j); dp[i] > cost) dp[i]= cost, x[i]= j;
};
auto rec= [&](auto &rec, int l, int r) {
if (r - l <= 1) return;
int m= (l + r) / 2;
for (int i= x[l]; i <= x[r]; ++i) check(m, i);
rec(rec, l, m);
for (int i= l + 1; i <= m; ++i) check(r, i);
rec(rec, m, r);
};
return dp[0]= 0, check(n, 0), rec(rec, 0, n), dp;
}
#line 7 "test/yukicoder/704.LARSCH.test.cpp"
using namespace std;
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
int n;
cin >> n;
long long a[n], x[n], y[n];
for (int i= 0; i < n; ++i) cin >> a[i];
for (int i= 0; i < n; ++i) cin >> x[i];
for (int i= 0; i < n; ++i) cin >> y[i];
auto f= [](long long x) { return abs(x); };
auto w= [&](int i, int j) { return f(x[j] - a[i - 1]) + f(y[j]); };
cout << simplified_larsch_dp(n, w)[n] << '\n';
return 0;
}
Env | Name | Status | Elapsed | Memory |
---|---|---|---|---|
g++-13 | 00_sample1.txt |
![]() |
6 ms | 4 MB |
g++-13 | 00_sample2.txt |
![]() |
5 ms | 4 MB |
g++-13 | 00_sample3.txt |
![]() |
5 ms | 4 MB |
g++-13 | 00_sample4.txt |
![]() |
5 ms | 4 MB |
g++-13 | 20_small1.txt |
![]() |
5 ms | 4 MB |
g++-13 | 20_small10.txt |
![]() |
5 ms | 4 MB |
g++-13 | 20_small2.txt |
![]() |
5 ms | 4 MB |
g++-13 | 20_small3.txt |
![]() |
5 ms | 4 MB |
g++-13 | 20_small4.txt |
![]() |
5 ms | 4 MB |
g++-13 | 20_small5.txt |
![]() |
5 ms | 4 MB |
g++-13 | 20_small6.txt |
![]() |
5 ms | 4 MB |
g++-13 | 20_small7.txt |
![]() |
5 ms | 4 MB |
g++-13 | 20_small8.txt |
![]() |
5 ms | 4 MB |
g++-13 | 20_small9.txt |
![]() |
5 ms | 4 MB |
g++-13 | 30_medium1.txt |
![]() |
5 ms | 4 MB |
g++-13 | 30_medium10.txt |
![]() |
5 ms | 4 MB |
g++-13 | 30_medium2.txt |
![]() |
5 ms | 4 MB |
g++-13 | 30_medium3.txt |
![]() |
5 ms | 4 MB |
g++-13 | 30_medium4.txt |
![]() |
5 ms | 4 MB |
g++-13 | 30_medium5.txt |
![]() |
5 ms | 4 MB |
g++-13 | 30_medium6.txt |
![]() |
5 ms | 4 MB |
g++-13 | 30_medium7.txt |
![]() |
5 ms | 4 MB |
g++-13 | 30_medium8.txt |
![]() |
5 ms | 4 MB |
g++-13 | 30_medium9.txt |
![]() |
5 ms | 4 MB |
g++-13 | 40_large1.txt |
![]() |
58 ms | 16 MB |
g++-13 | 40_large10.txt |
![]() |
61 ms | 16 MB |
g++-13 | 40_large2.txt |
![]() |
61 ms | 16 MB |
g++-13 | 40_large3.txt |
![]() |
62 ms | 16 MB |
g++-13 | 40_large4.txt |
![]() |
62 ms | 16 MB |
g++-13 | 40_large5.txt |
![]() |
60 ms | 16 MB |
g++-13 | 40_large6.txt |
![]() |
59 ms | 16 MB |
g++-13 | 40_large7.txt |
![]() |
61 ms | 16 MB |
g++-13 | 40_large8.txt |
![]() |
61 ms | 16 MB |
g++-13 | 40_large9.txt |
![]() |
62 ms | 16 MB |
g++-13 | 50_large_binary1.txt |
![]() |
63 ms | 16 MB |
g++-13 | 50_large_binary10.txt |
![]() |
63 ms | 16 MB |
g++-13 | 50_large_binary2.txt |
![]() |
61 ms | 16 MB |
g++-13 | 50_large_binary3.txt |
![]() |
60 ms | 16 MB |
g++-13 | 50_large_binary4.txt |
![]() |
61 ms | 16 MB |
g++-13 | 50_large_binary5.txt |
![]() |
60 ms | 16 MB |
g++-13 | 50_large_binary6.txt |
![]() |
60 ms | 16 MB |
g++-13 | 50_large_binary7.txt |
![]() |
62 ms | 16 MB |
g++-13 | 50_large_binary8.txt |
![]() |
61 ms | 16 MB |
g++-13 | 50_large_binary9.txt |
![]() |
61 ms | 16 MB |
g++-13 | 99_corner1.txt |
![]() |
6 ms | 4 MB |
g++-13 | 99_corner2.txt |
![]() |
5 ms | 4 MB |
g++-13 | 99_corner3.txt |
![]() |
60 ms | 16 MB |
g++-13 | 99_corner4.txt |
![]() |
61 ms | 16 MB |
clang++-18 | 00_sample1.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 00_sample2.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 00_sample3.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 00_sample4.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 20_small1.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 20_small10.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 20_small2.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 20_small3.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 20_small4.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 20_small5.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 20_small6.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 20_small7.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 20_small8.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 20_small9.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 30_medium1.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 30_medium10.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 30_medium2.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 30_medium3.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 30_medium4.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 30_medium5.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 30_medium6.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 30_medium7.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 30_medium8.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 30_medium9.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 40_large1.txt |
![]() |
53 ms | 16 MB |
clang++-18 | 40_large10.txt |
![]() |
55 ms | 16 MB |
clang++-18 | 40_large2.txt |
![]() |
57 ms | 16 MB |
clang++-18 | 40_large3.txt |
![]() |
57 ms | 16 MB |
clang++-18 | 40_large4.txt |
![]() |
56 ms | 16 MB |
clang++-18 | 40_large5.txt |
![]() |
57 ms | 16 MB |
clang++-18 | 40_large6.txt |
![]() |
54 ms | 16 MB |
clang++-18 | 40_large7.txt |
![]() |
55 ms | 16 MB |
clang++-18 | 40_large8.txt |
![]() |
56 ms | 16 MB |
clang++-18 | 40_large9.txt |
![]() |
56 ms | 16 MB |
clang++-18 | 50_large_binary1.txt |
![]() |
58 ms | 16 MB |
clang++-18 | 50_large_binary10.txt |
![]() |
57 ms | 16 MB |
clang++-18 | 50_large_binary2.txt |
![]() |
56 ms | 16 MB |
clang++-18 | 50_large_binary3.txt |
![]() |
55 ms | 16 MB |
clang++-18 | 50_large_binary4.txt |
![]() |
56 ms | 16 MB |
clang++-18 | 50_large_binary5.txt |
![]() |
54 ms | 16 MB |
clang++-18 | 50_large_binary6.txt |
![]() |
56 ms | 16 MB |
clang++-18 | 50_large_binary7.txt |
![]() |
58 ms | 16 MB |
clang++-18 | 50_large_binary8.txt |
![]() |
56 ms | 16 MB |
clang++-18 | 50_large_binary9.txt |
![]() |
56 ms | 16 MB |
clang++-18 | 99_corner1.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 99_corner2.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 99_corner3.txt |
![]() |
56 ms | 16 MB |
clang++-18 | 99_corner4.txt |
![]() |
57 ms | 16 MB |