이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
ll a[200001];
vector<pair<ll, bool>> v;
ll f(ll af, ll bf, ll df){
if(bf-af+1>df-bf){
return (a[df]-a[bf])-(a[bf]-a[af-1])+((bf-af+1)-(df-bf))*v[bf+1].F;
}
else{
return (a[df]-a[bf])-(a[bf]-a[af-1])-((df-bf)-(bf-af+1))*v[bf].F;
}
}
long long min_total_length(vector<int> r, vector<int> b) {
ll n=r.size(), m=b.size(), c[20];
for(int i=0; i<n; i++)v.push_back({r[i], 0});
for(int i=0; i<m; i++)v.push_back({b[i], 1});
if(r[0]<b[0])
v.push_back({0, 1});
else v.push_back({0, 0});
sort(v.begin(), v.end());
ll dp[v.size()];
c[0]=-1;
c[1]=-1;
dp[0]=0;
a[0]=0;
for(int i=1; i<v.size(); i++){
a[i]=v[i].F+a[i-1];
}
return f(1, n, n+m);
for(int i=1; i<v.size(); i++){
if(i+1<v.size())if(v[i].S==v[i+1].S)continue;
if(v[i].S==0){
dp[i]=1000000000000000ll;
if(c[1]!=-1){
for(int t=c[1]; v[t].S==1; t--)dp[i]=min(dp[i], f(t, c[1], i)+min(dp[t], dp[t-1]));
}
c[0]=i;
}
else{
dp[i]=1000000000000000ll;
if(c[0]!=-1){
for(int t=c[0]; v[t].S==0; t--)dp[i]=min(dp[i], f(t, c[0], i)+min(dp[t], dp[t-1]));
}
c[1]=i;
}
cout << dp[i] << " ";
}
return dp[n+m];
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i=1; i<v.size(); i++){
| ~^~~~~~~~~
wiring.cpp:34:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int i=1; i<v.size(); i++){
| ~^~~~~~~~~
wiring.cpp:35:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | if(i+1<v.size())if(v[i].S==v[i+1].S)continue;
| ~~~^~~~~~~~~
# | 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... |