이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |