이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
#include "wiring.h"
ll min_total_length(vector<int> r_g, vector<int> b_g) {
vi r, b;
for (int x : r_g)
r.pb(x);
for (int x : b_g)
b.pb(x);
int N = r.size();
int M = b.size();
map<ii, ll> dp;
// dp[i][j]: min cost to connect first i red (exclusive)
// with first j blue (exclusive)
dp[{0, 0}] = 0;
for (int i = 1; i <= N; i++) {
for (int j = max(i - 10, 1); j <= min(i + 10, M); j++) {
dp[{i, j}] = 1e18;
if (dp.find({i, j - 1}) != dp.end())
dp[{i, j}] = min(dp[{i, j}], dp[{i, j - 1}] + abs(r[i - 1] - b[j - 1]));
if (dp.find({i - 1, j}) != dp.end())
dp[{i, j}] = min(dp[{i, j}], dp[{i - 1, j}] + abs(r[i - 1] - b[j - 1]));
if (dp.find({i - 1, j - 1}) != dp.end())
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 time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |