Submission #1060924

#TimeUsernameProblemLanguageResultExecution timeMemory
1060924vjudge1전선 연결 (IOI17_wiring)C++17
7 / 100
141 ms262144 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 +1][m + 1], 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][j]);	
  /*
  for(int i = 0; i <= n; i ++)
    for(int j = 0; j <= m; j ++)
      cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
  */
  ans = dp[n][m];
  return ans;
}
/*
int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(m);
  for(int i = 0; i < n; i ++) cin >> a[i];
  for(int i = 0; i < m ; i ++) cin >> b[i];

  min_total_length(a, b);
  return 0;
}
*/
#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...