이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
long long min_total_length(std::vector<int> r, std::vector<int> b) {
vector<ii> arr;
for(int i = 0;i < r.size();i++)
arr.push_back(ii(r[i],0));
for(int i = 0;i < b.size();i++)
arr.push_back(ii(b[i],1));
int n = arr.size();
sort(arr.begin(),arr.end());
long long dp[n+1];
dp[0] = 0;
fill(dp,dp+n+1,0);
int color = arr[0].second;
vector<vector<ii> > groups;
vector<ii> v;
for(int i =0;i < n;i++){
if(color != arr[i].second){
groups.push_back(v);
v.clear();
color = arr[i].second;
}
v.push_back(ii(arr[i].first,i));
}
groups.push_back(v);
for(int gno = 0; gno < groups.size();gno++){
if(gno == 0)
for(int i = 0;i < groups[gno].size();i++){
int index = groups[gno][i].second;
dp[index+1] = 10234567890123456;
}
else{
long long acc = 0;
long long passed = 1023456789012345678;
int m = groups[gno-1].size();
long long dpp[m];
long long premin[m];
fill(dpp,dpp+m,0);
long long cursmol = 0;
long long prebig = -1;
for(int i = 0;i < groups[gno].size();i++){
if(i == 0){
for(int j = m-1;j>=0;j--){
dpp[j] = groups[gno][i].first - groups[gno-1][j].first;
if(j != m-1) dpp[j] += dpp[j+1];
}
long long minval = 1023456789012345678;
for(int j = 0;j < m;j++){
dpp[j] += dp[groups[gno-1][j].second];
//printf("%lld ",dpp[j]);
prebig = max(prebig,(long long)groups[gno-1][j].first);
minval = min(minval,dpp[j]);
}
premin[0] = dpp[0];
for(int j = 1;j < m;j++){
premin[j] = min(dpp[j],premin[j-1]);
}
minval = min(groups[gno][i].first - prebig + dp[groups[gno][i].second],minval);
dp[groups[gno][i].second+1] = minval;
cursmol = groups[gno][i].first;
}
else{
passed += (cursmol - prebig);
acc += groups[gno][i].first - cursmol;
long long minval = groups[gno][i].first - prebig;
minval += dp[groups[gno][i].second];
if(m-i-1>=0)
minval = min(minval,premin[m-i-1] + acc);
if(m-i>=0)
passed = min(passed,dpp[m-i] + (cursmol - prebig));
minval = min(minval, passed + acc);
dp[groups[gno][i].second+1] = minval;
}
}
}
}
return dp[n];
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:7:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0;i < r.size();i++)
~~^~~~~~~~~~
wiring.cpp:9:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0;i < b.size();i++)
~~^~~~~~~~~~
wiring.cpp:28:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int gno = 0; gno < groups.size();gno++){
~~~~^~~~~~~~~~~~~~~
wiring.cpp:30:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0;i < groups[gno].size();i++){
~~^~~~~~~~~~~~~~~~~~~~
wiring.cpp:43:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0;i < groups[gno].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... |