Submission #600039

#TimeUsernameProblemLanguageResultExecution timeMemory
600039DanShadersWiring (IOI17_wiring)C++17
17 / 100
1094 ms7048 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]; ll min_total_length(vector<int> r, vector<int> b) { // ll balance = sz(b) - sz(r); // ll ans = 0; // if (balance < 0) { // ans -= b[0] * balance; // } else { // ans -= r.back() * balance; // } // ans += accumulate(all(b), 0ll); // ans -= accumulate(all(r), 0ll); // return ans; 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)); fill(all(dp), +INF); dp[0] = 0; int k = sz(a); 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}; } // cout << lst.x << " " << lst.y << endl; if (lst.y) { for (int j = lst.x; j <= lst.y; ++j) { // cout << j << endl; 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; } for (int h = j; h < lst.y; ++h) { ans -= a[h].x; } for (int h = lst.y; h <= i; ++h) { ans += a[h].x; } if (dp[i + 1] > ans + dp[j]) { dp[i + 1] = ans + dp[j]; } } } } // for (int i = 0; i <= k; ++i) { // cout << dp[i] << " "; // } // cout << "\n"; 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...