Submission #298222

#TimeUsernameProblemLanguageResultExecution timeMemory
298222dantoh000Wiring (IOI17_wiring)C++14
0 / 100
1 ms384 KiB
#include <bits/stdc++.h> #define fi first #define se second using namespace std; typedef long long ll; typedef pair<int,int> ii; const ll INF = 1000000000000000000; //#include "wiring.h" ll dp[200005]; ll p[200005]; int last[200005]; vector<ii> v; ll min_total_length(vector<int> r, vector<int> b) { int nr = r.size(), nb = b.size(); int n = nr+nb; for (auto x: r) v.push_back({x,0}); for (auto x: b) v.push_back({x,1}); sort(v.begin(),v.end()); last[0] = -1; dp[0] = 0; p[0] = v[0].fi; for (int i = 1; i < n; i++){ dp[i] = INF; last[i] = (v[i].se == v[i-1].se) ? last[i-1] : i-1; p[i] = p[i-1] + v[i].fi; if (last[i] == -1) continue; dp[i] = dp[i-1] + v[i].fi - v[last[i]].fi; int pos = last[i]-(i-last[i]); if (last[last[i]] <= pos){ dp[i] = min(dp[i],dp[pos]+p[i]-p[last[i]]-(p[last[i]]-p[pos])); } //printf("%d ",dp[i]); } return dp[n-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...