제출 #1060907

#제출 시각아이디문제언어결과실행 시간메모리
1060907vjudge1전선 연결 (IOI17_wiring)C++17
0 / 100
1 ms348 KiB
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

ll min_total_length(vector<int> r, vector<int> b)
{
  ll ans = 0;
  int n = r.size(), m = b.size();

  ll dp[n][m], inf = 1e18;

  for(int i = 0; i <= n; i ++)
    for(int j = 0; j <= m; j ++)
      dp[i][j] = inf;

  dp[0][0] = 0;
  for(int i = 0; i < n; i ++)
    for(int j = 0; j < m; j ++)
      dp[i + 1][j + 1] = abs(r[i] - b[j]) + min(min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]);	
  
  ans = dp[n][m];
  return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...