이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <set>
typedef long long llong;
const int MAXN = 1000 + 10;
const llong INF = 1e18;
int n, m;
int r[MAXN];
int b[MAXN];
bool bl[MAXN][MAXN];
llong dp[MAXN][MAXN];
llong f(int lPtr, int rPtr)
{
if (lPtr == n && rPtr == m+1) return 0;
if (lPtr == n+1 || rPtr == m+1) return INF;
if (bl[lPtr][rPtr]) return dp[lPtr][rPtr];
bl[lPtr][rPtr] = true;
dp[lPtr][rPtr] = INF;
dp[lPtr][rPtr] = std::min(dp[lPtr][rPtr], f(lPtr, rPtr + 1) + abs(r[lPtr] - b[rPtr]));
dp[lPtr][rPtr] = std::min(dp[lPtr][rPtr], f(lPtr + 1, rPtr + 1) + abs(r[lPtr + 1] - b[rPtr]));
return dp[lPtr][rPtr];
}
long long min_total_length(std::vector <int> R, std::vector <int> B)
{
if (R.size() > B.size()) std::swap(R, B);
n = R.size();
m = B.size();
for (int i = 1 ; i <= n ; ++i)
{
r[i] = R[i-1];
}
for (int i = 1 ; i <= m ; ++i)
{
b[i] = B[i-1];
}
return f(1, 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... |