이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <iostream>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const ll inf=1e16;
int n, m;
pair < int, bool > svi[maxn];
ll pref[maxn];
ll dp[maxn];
inline ll dist(int ind1, int ind2){
return abs(svi[ind1].first-svi[ind2].first);
}
ll min_total_length(vector < int > r, vector < int > b){
n=r.size();
m=b.size();
for(int i=0; i<n; i++){
svi[i]={r[i], 0};
}
for(int i=0; i<m; i++){
svi[i+n]={b[i], 1};
}
sort(svi, svi+n+m);
for(int i=0; i<n+m; i++){
pref[i+1]=pref[i]+svi[i].first;
}
int zadnji[]={-1, -1};
zadnji[svi[0].second]=svi[0].first;
dp[1]=inf;
int visak;
int pivot;
int l, d;
for(int i=1; i<n+m; i++){
if(svi[i].second!=svi[i-1].second){
pivot=svi[i].first;
l=i-1;
d=i-1;
while(l>-1 && svi[l].second==svi[i-1].second){
l--;
}
// cout << opcije.size() << endl;
visak=0;
while(d-1>l && (dp[d]==inf || min(dp[d], dp[d+1])+(ll)(visak+1)*svi[i].first-(pref[i]-pref[d])>min(dp[d-1], dp[d])+(ll)(visak+2)*svi[i].first-(pref[i]-pref[d-1]))){
visak++;
d--;
}
// cout << dp[opcije.back()] << ' ' << (visak+1)*svi[i].first-(pref[i]-pref[opcije.back()]) << endl;
dp[i+1]=min(dp[d], dp[d+1])+(ll)(visak+1)*svi[i].first-(pref[i]-pref[d]);
}
else{
if(dp[i]==inf){
dp[i+1]=inf;
zadnji[svi[i].second]=svi[i].first;
continue;
}
if(visak){
dp[i+1]=dp[i]+svi[i].first-pivot;
visak--;
}
else{
if(d-1>l && dp[d]>dp[d-1]+dist(d-1, zadnji[svi[i].second^1])){
cout << "usaoo" << endl;
dp[i+1]=dp[i]-dp[d]+dp[d-1]+dist(d-1, zadnji[svi[i].second^1]);
d--;
}
else{
dp[i+1]=dp[i];
}
// cout << svi[i].first-zadnji[svi[i].second^1] << endl;
dp[i+1]+=svi[i].first-zadnji[svi[i].second^1];
}
}
zadnji[svi[i].second]=svi[i].first;
}
/* for(int i=0; i<=n+m; i++){
cout << dp[i] << ' ';
}
cout << endl;*/
return dp[n+m];
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'll min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:73:24: warning: 'd' may be used uninitialized in this function [-Wmaybe-uninitialized]
73 | dp[i+1]=dp[i]-dp[d]+dp[d-1]+dist(d-1, zadnji[svi[i].second^1]);
| ~~~~^
wiring.cpp:71:14: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
71 | if(d-1>l && dp[d]>dp[d-1]+dist(d-1, zadnji[svi[i].second^1])){
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wiring.cpp:67:32: warning: 'pivot' may be used uninitialized in this function [-Wmaybe-uninitialized]
67 | dp[i+1]=dp[i]+svi[i].first-pivot;
| ^~~~~
wiring.cpp:68:10: warning: 'visak' may be used uninitialized in this function [-Wmaybe-uninitialized]
68 | visak--;
| ~~~~~^~
# | 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... |