이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
#define pb push_back
#define popb pop_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
const int nax = 205;
const ll INF = 1e18;
int n, m;
vll A, B;
ll dp[nax][nax];
int f(int i, int j)
{
if(i >= n && j >= m)
return 0ll;
if(dp[i][j] != -1)
return dp[i][j];
ll br = INF, rb = INF, bt = INF ;
if(j != 0 && i != n)
br = f(i + 1,j) + abs(A[i] - B[j - 1]);
if(i != 0 && j != n)
rb = f(i, j + 1) + abs(A[i - 1] - B[j]);
if(i != n && j != n)
bt = f(i +1, j+ 1) + abs(A[i] - B[j]);
return dp[i][j] = min(bt,min(rb, br));
}
ll min_total_length(vi r, vi b)
{
n = r.size(), m = b.size();
sort(all(r));
sort(all(b));
for(auto e: r)
A.pb(e);
for(auto e: b)
B.pb(e);
memset(dp, -1,sizeof(dp));
return f(0, 0);
}
# | 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... |