제출 #600052

#제출 시각아이디문제언어결과실행 시간메모리
600052DanShaders전선 연결 (IOI17_wiring)C++17
17 / 100
1085 ms10152 KiB
//grader.cpp #include "wiring.h" #include <bits/stdc++.h> using namespace std; #define x first #define y second #define all(x) begin(x), end(x) #define sz(x) ((int) (x).size()) using ll = long long; using ld = long double; const int N = 2e5 + 10; const ll INF = 0x3f3f3f3f3f3f3f3f; ll dp[N], pref[N], fend[N]; ll min_total_length(vector<int> r, vector<int> b) { vector<pair<int, int>> a; for (int u : r) { a.push_back({u, 0}); } for (int u : b) { a.push_back({u, 1}); } sort(all(a)); int k = sz(a); fend[k - 1] = k; for (int i = k - 1; i--; ) { if (a[i].y != a[i + 1].y) { fend[i] = i + 1; } else { fend[i] = fend[i] + 1; } } for (int i = 0; i < k; ++i) { pref[i + 1] = pref[i] + a[i].x; } fill(all(dp), +INF); dp[0] = 0; pair<int, int> lst = {0, 0}; for (int i = 0; i < k; ++i) { if (i && a[i].y != a[i - 1].y) { lst = {lst.y, i}; } if (lst.y) { for (int j = lst.x; j <= lst.y; ++j) { ll balance = i + j - 2 * lst.y + 1, ans = 0; if (balance < 0) { ans -= a[lst.y].x * balance; } else { ans -= a[lst.y - 1].x * balance; } ans -= pref[lst.y] - pref[j]; ans += pref[i + 1] - pref[lst.y]; if (dp[i + 1] > ans + dp[j]) { dp[i + 1] = ans + dp[j]; } } } } 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...