이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false); cin.tie(0);
#define pre(a) cout << fixed; cout.precision(a)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define em emplace
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;
int n, m;
ll c[200010];
ll dp[200010];
long long min_total_length(std::vector<int> r, std::vector<int> b) {
n = r.size() + b.size();
vector<pii> v;
v.eb(-inf, 0);
for(auto i : r) v.eb(i, 0);
for(auto i : b) v.eb(i, 1);
sort(all(v));
ll R = -INF, B = -INF;
for(int i=1; i<=n; i++) {
if(v[i].se == 0) R = v[i].fi;
else B = v[i].fi;
c[i] = abs(R - B);
}
R = INF, B = INF;
for(int i=n; i > 0; i--) {
if(v[i].se == 0) R = v[i].fi;
else B = v[i].fi;
c[i] = min(c[i], abs(R - B));
}
int t = 0;
ll sum = 0;
for(int i=1; i<=n; i++) {
dp[i] = dp[i-1] + c[i];
if(i-1 > 0 && v[i-1].se != v[i].se) {
t = 1;
sum = v[i].fi - v[i-1].fi;
dp[i] = min(dp[i], dp[i-2] + sum);
}
else if(i-2*t-1 > 0 && v[i-2*t-1].se != v[i].se) {
t++;
sum += v[i].fi - v[i-2*t+1].fi;
dp[i] = min(dp[i], dp[i-2*t] + sum);
}
else t = 0, sum = 0;
}
return dp[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... |