제출 #395375

#제출 시각아이디문제언어결과실행 시간메모리
395375idk321전선 연결 (IOI17_wiring)C++11
7 / 100
34 ms8112 KiB
#include "wiring.h"

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 205;
ll dp[N][N][4];
const ll M = 1000000000000000000LL;

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++)
        {
            for (int k = 0; k < 4; k++) dp[i][j][k] = M;
        }
    }

    dp[0][0][0] = 0;
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= m; j++)
        {
            for (int k = 0; k < 4; k++)
            {
                if (i < n)
                {
                    if (i == 0 || k & 1)
                    {
                         dp[i + 1][j][k & 2] = min(dp[i][j][k], dp[i + 1][j][k & 2]);

                        if (j != 0) dp[i + 1][j][3] = min(dp[i][j][k] + abs(r[i] - b[j - 1]), dp[i + 1][j][3]);
                        //cout << i << " " <<j << " " << dp[i + 1][j][3] << endl;
                    }

                }
                if (j < m)
                {
                    if (j == 0 || k & 2)
                    {
                        dp[i][j + 1][k & 1] = min(dp[i][j][k], dp[i][j + 1][k & 1]);
                        if (i != 0) dp[i][j + 1][3] = min(dp[i][j][k] + abs(r[i - 1] - b[j]), dp[i][j + 1][3]);
                    }
                }

                //cout << i << " " << j << " " << k << " "<< dp[i][j][k] << endl;
            }


        }
    }

	return dp[n][m][3];
}
#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...