이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#include "wiring.h"
#define ll long long
#define all(v) v.begin() , v.end()
#define sz(a) (ll)a.size()
using namespace std;
const ll INF = 1e18;
ll min_total_length(vector<int> R, vector<int> B){
ll n = sz(R), m = sz(B);
ll ar[n+5],ar2[m+5];
for(ll i=0;i<n;i++) ar[i] = R[i];
for(ll i=0;i<m;i++) ar2[i] = B[i];
array<ll,2> range[n+5];
for(ll i=0;i<n;i++){
ll l = lower_bound(ar2,ar2+m,(i>0 ? ar[i-1] : -1)) - ar2;
ll r = lower_bound(ar2,ar2+m,(i+1<n ? ar[i+1] : INF)) - ar2;
l = max(0LL, l - 1);
r = min(m-1, r + 1);
range[i][0] = l;
range[i][1] = r;
}
ll dp[n+5][m+5];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
ll cur = INF;
if(i==0 && j==0) cur = 0;
if(i && j)cur = min(cur, dp[i-1][j-1]);
if(j) cur = min(cur, dp[i][j-1]);
if(i) cur = min(cur, dp[i-1][j]);
dp[i][j] = cur + abs(ar[i] - ar2[j]);
}
}
return dp[n-1][m-1];
}
/*void _(){
ll n,m;
cin >> n >> m;
ll ar[n+5],ar2[m+5];
for(ll i=0;i<n;i++) cin >> ar[i];
for(ll i=0;i<m;i++) cin >> ar2[i];
array<ll,2> range[n+5];
for(ll i=0;i<n;i++){
ll l = lower_bound(ar2,ar2+m,(i>0 ? ar[i-1] : -1)) - ar2;
ll r = lower_bound(ar2,ar2+m,(i+1<m ? ar[i+1] : INF)) - ar2;
l--;
r++;
l = max(0LL, l);
r = min(m-1, r);
range[i][0] = l;
range[i][1] = r;
}
ll dp[n+5][m+5];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
ll cur = INF;
if(i==0 && j==0) cur = 0;
if(i && j)cur = min(cur, dp[i-1][j-1]);
if(j) cur = min(cur, dp[i][j-1]);
if(i) cur = min(cur, dp[i-1][j]);
dp[i][j] = cur + abs(ar[i] - ar2[j]);
}
}
cout << dp[n-1][m-1] << '\n';
}
int32_t main(){
cin.tie(0); ios::sync_with_stdio(0);
ll tc=1;//cin >> tc;
while(tc--) _();
return 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... |