이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <bits/stdc++.h>
#define pos first
#define col second
using namespace std;
using ll = long long;
const int N = 2e5+1;
const ll INF = 1e17;
int n;
vector<pair<int,int> > a;
ll s[N], dp[N];
inline ll fl(int j, int k) { // j, k part of sum when i-k < k-j
return dp[j] + s[j] - 2*s[k] - 1ll * (j-2*k) * a[k+1].pos;
}
inline ll fg(int j, int k) {
return dp[j] + s[j] - 2*s[k] - 1ll * (j-2*k) * a[k].pos;
}
set<pair<ll,int> > stl, stg; // l: j <= 2*k-i, g: j > 2*k-i
ll min_total_length(std::vector<int> r, std::vector<int> b) {
n = r.size() + b.size();
for(int i = 0; i < r.size(); i++) a.emplace_back(r[i], 0);
for(int i = 0; i < b.size(); i++) a.emplace_back(b[i], 1);
a.emplace_back(INT_MIN, INT_MIN);
sort(a.begin(), a.end());
for(int i = 1; i <= n; i++) s[i] = s[i-1] + a[i].pos;
fill(dp+1, dp+n+1, INF);
for(int i = 2, k = 0; i <= n; i++) {
if(a[i].col != a[i-1].col) {
k = i-1;
stl.clear();
stg.clear();
for(int j = k-1; j >= 0 && a[j+1].col == a[k].col; j--)
stl.emplace(fl(j, k), j);
}
if(!k) continue;
// case segments completely disjoint
if(!stl.empty()) dp[i] = min(stl.begin()->first + s[i] - 1ll * i * a[k+1].pos, dp[i]);
if(!stg.empty()) dp[i] = min(stg.begin()->first + s[i] - 1ll * i * a[k].pos, dp[i]);
if(!stl.empty()) {
stl.erase(make_pair(fl(2*k-i, k), 2*k-i));
stg.emplace(make_pair(fg(2*k-i, k), 2*k-i));
}
// special case: segments intersect at one node
if(k-1 >= 1 && a[k-1].col == a[i].col)
dp[i] = min(dp[k] + s[i] - s[k] - 1ll * (i-k) * a[k].pos, dp[i]);
}
return dp[n];
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'll min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:22:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < r.size(); i++) a.emplace_back(r[i], 0);
^
wiring.cpp:23:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < b.size(); i++) a.emplace_back(b[i], 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... |