제출 #428422

#제출 시각아이디문제언어결과실행 시간메모리
428422vanic전선 연결 (IOI17_wiring)C++14
0 / 100
1 ms204 KiB
#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; } dp[1]=inf; int l, d; int br=0; ll curr; ll val; ll sol; for(int i=1; i<n+m; i++){ if(svi[i].second!=svi[i-1].second){ l=i-1; d=i-1; while(l>-1 && svi[l].second==svi[i-1].second){ l--; } br=1; } if(!br){ dp[i+1]=inf; continue; } // cout << l << ' ' << d << endl; val=0; for(int j=d+2; j<=i; j++){ val+=svi[j].first-svi[d+1].first; } curr=val; sol=inf; // cout << "br " << br << endl; for(int j=d; j>l; j--){ if(j==d){ curr+=(ll)(svi[d+1].first-svi[j].first)*br; } else if(d-j<br){ // cout << "no no no" << endl; curr+=svi[j+1].first-svi[j].first; } else{ curr+=svi[d+1].first-svi[j].first; } // cout << curr << ' '; sol=min(sol, curr+dp[j]); } // cout << endl; dp[i+1]=sol; br++; } /* for(int i=0; i<=n+m; i++){ cout << dp[i] << ' '; } cout << endl;*/ return dp[n+m]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...