이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int>vi;
#define pb push_back
#define sz(v) (int)v.size()
#define FOR(i,a,b) for(int i=a; i<b; i++)
//------------------------------------
int N,M;
vi a(500),b(500);
ll memo[500][500];
ll solve(int i, int j){
if(i==N){
if(j<M) return 1e18;
return 0;
}
ll ind=memo[i][j];
if(ind!=-1) return ind;
ll ans=1e18,val=0;
FOR(k,max(0,j-1),M){
val+=abs(b[k]-a[i]);
ll x=solve(i+1,k+1)+val;
if(x<ans) ans=x;
}
val=0;
FOR(k,j,M){
val+=abs(b[k]-a[i]);
ll x=solve(i+1,k+1)+val;
if(x<ans) ans=x;
}
return ind=ans;
}
ll min_total_length(vi a, vi b) {
N=sz(a),M=sz(b);
FOR(i,0,N) ::a[i]=a[i];
FOR(i,0,M) ::b[i]=b[i];
memset(memo,-1,sizeof(memo));
return solve(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... |