이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 200005, inf = 1e9+7;
int n;
pii a[N];
ll s[N], dt[N];
long long min_total_length(std::vector<int> r, std::vector<int> b) {
for(auto &T : r) a[++n] = {T, 0};
for(auto &T : b) a[++n] = {T, 1};
sort(a+1, a+1+n);
a[0] = {-inf, 1-a[1].Y};
for(int i=1;i<=n;i++) {
s[i] = s[i-1] + a[i].X;
}
for(int i=1,p=1;i<=n;i++) {
int j = i;
while(j<n && a[j+1].Y == a[i].Y) j++;
for(int k=p;k<i;k++) {
dt[k] = min(dt[k], dt[k-1] + a[i].X - a[k].X);
}
ll C = 0, M = dt[i-1];
for(int k=i;k<=j;k++) {
C += a[k].X - a[i-1].X;
int X = 2*i-2-k;
if(X+1 >= p) {
M = min(M, dt[X] + 1ll * a[i-1].X * (i-1-X) - s[i-1] + s[X]);
}
dt[k] = C + M;
}
p = i;
i = j;
}
return dt[n];
}
| # | 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... |