제출 #420295

#제출 시각아이디문제언어결과실행 시간메모리
420295temurbek_khujaev전선 연결 (IOI17_wiring)C++17
7 / 100
115 ms7988 KiB
#include <bits/stdc++.h>
#include "wiring.h"

using namespace std;
#define N 402
long long dp[N][N];
const long long INF = 1e18;

long long min_total_length(std::vector<int> r, std::vector<int> b) {
    int n = r.size();
    int m = b.size();
    for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) dp[i][j] = INF;
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + abs(r[i - 1] - b[j - 1]);
            dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + abs(r[i - 1] - b[j - 1]));
        }
    }
    return dp[n][m];

}
#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...