Submission #284383

#TimeUsernameProblemLanguageResultExecution timeMemory
284383DystoriaXWiring (IOI17_wiring)C++14
13 / 100
61 ms9964 KiB
#include "wiring.h" #include <algorithm> #include <iostream> #include <set> using namespace std; vector<pair<int, int> > v; const long long INF = 1e17; long long dp[200010], pref[200010]; int st[200010], en[200010]; long long min_total_length(std::vector<int> r, std::vector<int> b) { int n = r.size() + b.size(); for(auto &k : r) v.emplace_back(k, 0); for(auto &k : b) v.emplace_back(k, 1); v.emplace_back(-1, -1); sort(v.begin(), v.end()); st[1] = 1; for(int i = 2; i <= n; i++){ if(v[i].second == v[i - 1].second) st[i] = st[i - 1]; else st[i] = i; } en[n] = n; for(int i = n - 1; i >= 1; i--){ if(v[i].second == v[i + 1].second) en[i] = en[i + 1]; else en[i] = i; } for(int i = 1; i <= n; i++){ dp[i] = INF; pref[i] = pref[i - 1] + v[i].first; if(en[i] != n) dp[i] = min(dp[i], dp[i - 1] + v[en[i] + 1].first - v[i].first); if(st[i] == 1) continue; if(st[i] == i){ dp[i] = min(dp[i], dp[i - 1]); } dp[i] = min(dp[i], dp[i - 1] + v[i].first - v[st[i] - 1].first); int len = i - st[i] + 1; if(st[i] - st[st[i] - 1] >= len) dp[i] = min(dp[i], dp[st[i] - len - 1] + (pref[i] - pref[st[i] - 1]) - (pref[st[i] - 1] - pref[st[i] - len - 1])); // cerr << i << " " << dp[i] << "\n"; } return dp[n]; }
#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...