이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_DIVERGENCE = 5;
const long long INF = 1e15;
long long min_total_length(vector<int> r, vector<int> b) {
vector<pair<int,int>> arr;
for(int&i:b)arr.emplace_back(i,0);
for(int&i:r)arr.emplace_back(i,1);
sort(arr.begin(), arr.end());
int n = arr.size();
arr.insert(arr.begin(),{-1,0});
vector DP(n+1,INF);
DP[0]=0;
for(int i=1;i<=n;i++) {
auto [idx,mycolour] = arr[i];
long long minmy,maxother;
int found = i;
long long sum = 0;
int cntMy = 0,cntOther = 0;
for(int j=i;j;j--) {
if(mycolour==arr[j].second) {
cntMy++;
minmy = arr[j].first;
sum+=arr[j].first;
} else {
found = j;
maxother=arr[j].first;
break;
}
}
if(found==i)continue;
for(int j=found;j;j--) {
if(arr[j].second==mycolour)break;
cntOther++;
sum-=arr[j].first;
int edges = max(cntMy,cntOther);
long long currcost = sum+(edges-cntMy)*minmy-(edges-cntOther)*maxother;
DP[i]=min(DP[i],min(DP[j-1],DP[j])+currcost);
}
}
return DP[n];
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:40:42: warning: 'minmy' may be used uninitialized in this function [-Wmaybe-uninitialized]
40 | long long currcost = sum+(edges-cntMy)*minmy-(edges-cntOther)*maxother;
| ~~~~~~~~~~~~~^~~~~~
# | 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... |