제출 #284217

#제출 시각아이디문제언어결과실행 시간메모리
284217DystoriaX전선 연결 (IOI17_wiring)C++14
0 / 100
1 ms384 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]; 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; } for(int i = 1; i <= n; i++){ dp[i] = INF; pref[i] = pref[i - 1] + v[i].first; if(st[i] == 1) continue; if(st[i] == i){ for(int k = i - 1; k >= st[i - 1]; k--){ dp[i] = min(dp[i], dp[k - 1] + 1LL * (i - k) * v[i].first - (pref[i - 1] - pref[k - 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[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...