이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
#define sz(a) int((a).size())
ii bop(stdvec& a, int x) {
if(x<a[0]) return {0,0};
if(x>a.back()) return {sz(a)-1,sz(a)-1};
int idx = lower_bound(all(a),x)-a.begin();
return {idx,idx+1};
}
int dist(stdvec& a, int x) {
ii ops = bop(a,x);
return min(abs(a[ops.x]-x),abs(a[ops.y]-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... |