This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#include "wiring.h"
#define fin(i,s,n) for(auto i = s; i < n; ++i)
#define fine(i,s,n) for(auto i = s; i <= n; ++i)
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
#define chkmin(a,b) a = min(a,b)
#define chkmax(a,b) a = max(a,b)
using stdvec = vector<int>;
#define int int64_t
using ii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vii = vector<ii>;
const int inf = 1e17;
int dist(stdvec& a, int x) {
if(x<=a[0]) return abs(a[0]-x);
if(x>=a.back()) return abs(a.back()-x);
auto it = lower_bound(all(a),x);
return min(abs(*it-x),abs(*(it+1)-x));
}
long long min_total_length(stdvec r, stdvec b) {
int n = r.size(), m = b.size();
vvi dp(n,vi(m,inf));
dp[0][0] = abs(r[0]-b[0]);
fin(i,0,n) {
if(i) dp[i][0] = dp[i-1][0]+abs(r[i]-b[0]);
fin(j,1,m) {
if(i) chkmin(dp[i][j],dp[i-1][j]+dist(b,r[i]));
chkmin(dp[i][j],dp[i][j-1]+dist(r,b[j]));
if(i) chkmin(dp[i][j],dp[i-1][j-1]+abs(r[i]-b[j]));
}
}
return dp[n-1][m-1];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |