이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include<bits/stdc++.h>
using namespace std;
long long min_total_length(std::vector<int> r, std::vector<int> b) {
long long n = r.size(),m = b.size();
vector<pair<long long,long long>> haha(n+m+1,{-1,-1});
for(long long i = 0; i < r.size(); i++) {
haha[i] = {r[i],0};
}
for(long long i = 0; i < m; i++) {
haha[i+n] = {b[i],1};
}
sort(haha.begin(),haha.end());
vector<long long> wow(n+m+1);
vector<long long> wut(n+m+1);
long long c = 0,sb = 0;
for(long long i = 1; i <= n+m; i++) {
if(i > 1 && haha[i].second != haha[i-1].second) {
c = haha[i].first;
sb = 0;
}
sb+=haha[i].first-c;
wow[i] = sb;
}
c = haha[n+m].first,sb = 0;
for(long long i = n+m; i >= 1; i--) {
if(i < n+m && haha[i].second != haha[i+1].second) {
c = haha[i].first;
sb = 0;
}
sb+=c-haha[i].first;
wut[i] = sb;
}
vector<long long> dp(n+m+1);
long long l = 0,sm = LLONG_MAX/2;
priority_queue<pair<long long,long long>> bruh;
for(long long i = 1; i <= n+m; i++) {
if(i != 1 && haha[i].second != haha[i-1].second) {
while(!bruh.empty()) {
bruh.pop();
}
sm = LLONG_MAX/2;
for(long long j = l; j < i; j++) {
bruh.push({-(dp[j]+wut[min(j+1,i-1)]+(i-j-1)*(haha[i].first-haha[i-1].first)),i-j-1});
}
l = i-1;
}
sm+=haha[l+1].first-haha[l].first;
dp[i] = LLONG_MAX/2;
while(!bruh.empty() && bruh.top().second < i-l) {
sm = min(sm,-bruh.top().first+(i-l-bruh.top().second)*(haha[l+1].first-haha[l].first));
bruh.pop();
}
dp[i] = min(sm,dp[i]);
if(!bruh.empty()) {
dp[i] = min(dp[i],-bruh.top().first);
}
dp[i]+=wow[i];
}
return dp[n+m];
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:8:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | for(long long i = 0; i < r.size(); i++) {
| ~~^~~~~~~~~~
# | 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... |