제출 #1203010

#제출 시각아이디문제언어결과실행 시간메모리
1203010LolkasMeep전선 연결 (IOI17_wiring)C++20
7 / 100
178 ms327680 KiB
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;

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

    ll dp[n][m];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            dp[i][j] = LLONG_MAX;
        }
    }

    dp[0][0] = abs(r[0] - b[0]);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(i > 0){
                dp[i][j] = min(dp[i][j], dp[i-1][j] + abs(r[i] - b[j]));
            }
            if(j > 0){
                dp[i][j] = min(dp[i][j], dp[i][j-1] + abs(r[i] - b[j]));
            }
            if(i > 0 && j > 0){
                dp[i][j] = min(dp[i][j], dp[i-1][j-1] + abs(r[i] - b[j]));
            }
        }
    }

    return dp[n-1][m-1];
}

// int main(){
//     int R[] = {1, 2, 3, 7};
//     int B[] = {0, 4, 5, 9, 10};
//     cout << min_total_length({1, 2, 3, 7}, {0, 4, 5, 9, 10}) << '\n';
//     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...