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 "wiring.h"
#include <bits/stdc++.h>
#define FOR(i,p,k) for(int i=(p);i<=(k);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define ssize(x) (int((x).size()))
#define all(x) (x).begin(),(x).end()
#define inf 1000000000000000000ll
using namespace std;
typedef long long ll;
ll min_total_length(vector<int> r, vector<int> b){
int n = ssize(r);
int m = ssize(b);
vector dp(n, vector(m, inf));
dp[0][0] = abs(r[0]-b[0]);
REP(i, n) REP(j, m){
if(i+1 < n) dp[i+1][j] = min(dp[i+1][j], dp[i][j] + abs(r[i+1]-b[j]));
if(j+1 < m) dp[i][j+1] = min(dp[i][j+1], dp[i][j] + abs(r[i]-b[j+1]));
if(i+1 < n && j+1 < m) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + abs(r[i+1]-b[j+1]));
}
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... |