이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
long long dp[2][2], cost[2];
int l[2], n[2];
vector <int> p[2];
#define pos(k) p[k][l[k]]
void minself(long long &a, long long b){
a = min(a, b);
}
long long min_total_length(vector <int> r, vector <int> b){
n[0] = r.size();
n[1] = b.size();
for (int a : r) p[0].push_back(a);
for (int a : b) p[1].push_back(a);
l[0] = 0;
l[1] = 0;
int last = -1;
for (int i = 0; i < n[0] + n[1]; ++ i){
int cur = 0;
if (l[0] == n[0] || (l[1] < n[1] && p[1][l[1]] < p[0][l[0]])) cur = 1;
cost[0] = inf;
cost[1] = inf;
if (l[cur ^ 1] < n[cur ^ 1]) cost[1] = pos(cur ^ 1) - pos(cur);
if (l[cur ^ 1] > 0) cost[1] = pos(cur) - p[cur ^ 1][l[cur ^ 1] - 1];
int state = i & 1;
for (int j : {0, 1}) dp[state][j] = inf;
if (!i) {
for (int j : {0, 1}) dp[state][j] = cost[j];
continue;
}
if (cur == last) for (int j : {0, 1}) for (int jlast : {0, 1}) minself(dp[state][j | jlast], dp[state ^ 1][jlast] + cost[j]);
else {
dp[state][0] = min(dp[state ^ 1][1], dp[state ^ 1][0] + cost[0]);
dp[state][1] = min(dp[state ^ 1][0], dp[state ^ 1][1]) + cost[1];
}
++ l[cur];
last = cur;
}
return min(dp[last][0], dp[last][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... |