제출 #137165

#제출 시각아이디문제언어결과실행 시간메모리
137165Mahdi_Jfri전선 연결 (IOI17_wiring)C++14
0 / 100
1071 ms7116 KiB
#include "wiring.h" #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back const int maxn = 2e5 + 20; ll dp[maxn]; vector<int> t[2]; long long min_total_length(vector<int> r, vector<int> b) { int n = r.size() , m = b.size(); int k = n + m; vector<pair<int , int> > a; for(auto x : r) a.pb({x , 0}); for(auto x : b) a.pb({x , 1}); sort(a.begin() , a.end()); memset(dp , 63 , sizeof dp); dp[0] = 0; for(int i = 0; i < k; i++) { int j = i; while(j >= 0 && a[j].second == a[i].second) j--; if(j < 0) continue; ll sum = 0; for(int x = j + 1; x <= i; x++) sum += a[x].first - a[j + 1].first; int sz2 = i - j; int x = j; while(x >= 0 && a[x].second == a[j].second) { sum += a[j].first - a[x].first; ll val = 1LL * (a[j + 1].first - a[j].first) * max(sz2 , j - x + 1); val += sum; dp[i + 1] = min(dp[i + 1] , dp[x] + val); x--; } } return dp[k]; }
#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...