이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll min_total_length(vector<int> r, vector<int> b) {
int n=r.size()+b.size();
vector<pair<ll,ll> > g;
g.push_back({-1,-1});
for(int i=0;i<r.size();i++)g.push_back({r[i],0});
for(int i=0;i<b.size();i++)g.push_back({b[i],1});
sort(g.begin(),g.end());
vector<ll>dp(n+1),pr(n+1),lst(3*n,-1);
vector<ll>prv={-1,-1};
ll s=0;
lst[n]=0;
for(int i=1;i<=n;i++)
{
pr[i]=pr[i-1]+(2*g[i].second-1)*g[i].first;
s+=2*g[i].second-1;
prv[g[i].second]=i;
if(prv[1-g[i].second]!=-1)
{
dp[i]=dp[i-1]+g[i].first-g[prv[1-g[i].second]].first;
if(lst[n+s]!=-1)
{
dp[i]=min(dp[i],dp[lst[n+s]]+abs(pr[i]-pr[lst[s+n]]));
}
}
else dp[i]=10000000000000000;
lst[n+s]=i;
}
return dp[n];
}
/*int main()
{
cout<<min_total_length({1, 2, 3, 7}, {0, 4, 5, 9, 10});
}
*/
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'll min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:9:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | for(int i=0;i<r.size();i++)g.push_back({r[i],0});
| ~^~~~~~~~~
wiring.cpp:10:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for(int i=0;i<b.size();i++)g.push_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... |