제출 #1154830

#제출 시각아이디문제언어결과실행 시간메모리
1154830alexdd전선 연결 (IOI17_wiring)C++20
7 / 100
1096 ms8836 KiB
#include "wiring.h" #include<bits/stdc++.h> using namespace std; #define int long long const int INF = 1e18; int dp[200005]; int tole[200005]; int pref[200005]; long long min_total_length(std::vector<int32_t> r, std::vector<int32_t> b) { vector<pair<int,int>> v; for(int x:r) v.push_back({x,0}); for(int x:b) v.push_back({x,1}); v.push_back({-1,-1}); sort(v.begin(),v.end()); int ult[2] = {0,0}; for(int i=1;i<v.size();i++) { ult[v[i].second] = i; tole[i] = ult[1-v[i].second]; pref[i] = pref[i-1] + v[i].first; } for(int i=1;i<v.size();i++) { dp[i]=INF; int ri = tole[i]; if(ri==0) continue; int le = tole[ri]+1; for(int j=le;j<=ri;j++) { int aux=0; //for(int u=j;u<=ri;u++) // aux += v[ri].first - v[u].first; aux += v[ri].first * (ri-j+1) - (pref[ri] - pref[j-1]); aux += max(ri-j+1, i-ri) * (v[ri+1].first - v[ri].first); dp[i] = min(dp[i], aux + dp[j-1]); } dp[i] += pref[i] - pref[ri] - v[ri+1].first * (i-ri); dp[i] = min(dp[i], INF); for(int j=i-1;j>0;j--) dp[j] = min(dp[j], dp[i]); } return dp[(int)v.size()-1]; } /* */
#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...