이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int nx=205;
ll dp[nx][nx];
vector<int> R, B;
ll greedyr(ll x)
{
ll res=LLONG_MAX;
for (auto y:B) res=min(res, abs(x-y));
return res;
}
ll greedyb(ll x)
{
ll res=LLONG_MAX;
for (auto y:R) res=min(res, abs(x-y));
return res;
}
long long min_total_length(std::vector<int> r, std::vector<int> b) {
R=r, B=b;
int n=r.size(), m=b.size();
for (int i=0; i<n; i++)
{
for (int j=0; j<m; j++)
{
dp[i][j]=LLONG_MAX;
if (i>0) dp[i][j]=min(dp[i][j], dp[i-1][j]+greedyr(r[i]));
if (j>0) dp[i][j]=min(dp[i][j], dp[i][j-1]+greedyb(b[j]));
if (i==0&&j==0) dp[i][j]=abs(r[i]-b[j]);
if (i>0&&j>0) dp[i][j]=min(dp[i][j], dp[i-1][j-1]+abs(r[i]-b[j]));
}
}
return dp[n-1][m-1];
}
/*
4 5
1 3 4 5
8 9 10 12 14
*/
# | 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... |