이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include "bits/stdc++.h"
#define ll long long
using namespace std;
const int sz = 2e5 + 10;
const ll inf = 1e18 + 18;
ll dp[sz][2];
ll min_total_length(vector<int> r, vector<int> b) {
    int n = r.size(), m = b.size();
    int i = 0, j = 0, k = 0;
    map<int,int> ma, mb;
    while (i < n and j < m) {
        if (r[i] < b[j]) {
            ma[i] = k;
            if (0 < j) {
                int l = mb[j - 1];
                dp[k][0] = dp[l][1] + r[i] - b[j - 1] + min(dp[k - 1][0], dp[k - 1][1]) - min(dp[l][0], dp[l][1]);
            } else dp[k][0] = inf;
            if (j < m) {
                if (0 < k) dp[k][1] = min(dp[k - 1][0], dp[k - 1][1]);
                dp[k][1] += b[j] - r[i];
            } else dp[k][1] = inf;
            i ++;
        } else {
            mb[j] = k;
            if (0 < j) {
                int l = ma[i - 1];
                dp[k][0] = dp[l][1] + b[j] - r[i - 1] + min(dp[k - 1][0], dp[k - 1][1]) - min(dp[l][0], dp[l][1]);
            } else dp[k][0] = inf;
            if (j < m) {
                if (0 < k) dp[k][1] = min(dp[k - 1][0], dp[k - 1][1]);
                dp[k][1] += r[i] - b[j];
            } else dp[k][1] = inf;
            j ++;
        }
        k ++;
    }
    return min(dp[k - 1][0], dp[k - 1][1]);
}
| # | 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... |